usr/src/uts/common/fs/zfs/dmu_objset.c
author Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
Tue, 18 May 2010 12:28:45 -0600
changeset 12432 222dd376dd6c
parent 12296 7cf402a7f374
child 12493 89ce40422cea
permissions -rw-r--r--
6952522 elpaso panics: assertion failed: refcount_is_zero(&dn->dn_holds), file: ../../common/fs/zfs/dnode.c
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
/*
12178
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
    22
 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    23
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    24
12294
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12178
diff changeset
    25
/* Portions Copyright 2010 Robert Milkowski */
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12178
diff changeset
    26
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3978
diff changeset
    27
#include <sys/cred.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    28
#include <sys/zfs_context.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    29
#include <sys/dmu_objset.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    30
#include <sys/dsl_dir.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    31
#include <sys/dsl_dataset.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    32
#include <sys/dsl_prop.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    33
#include <sys/dsl_pool.h>
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
    34
#include <sys/dsl_synctask.h>
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3978
diff changeset
    35
#include <sys/dsl_deleg.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    36
#include <sys/dnode.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    37
#include <sys/dbuf.h>
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
    38
#include <sys/zvol.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    39
#include <sys/dmu_tx.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>
11165
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11022
diff changeset
    44
#include <sys/sunddi.h>
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
    45
#include <sys/sa.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    46
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    47
spa_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    48
dmu_objset_spa(objset_t *os)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    49
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
    50
	return (os->os_spa);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    51
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    52
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    53
zilog_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    54
dmu_objset_zil(objset_t *os)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    55
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
    56
	return (os->os_zil);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    57
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    58
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    59
dsl_pool_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    60
dmu_objset_pool(objset_t *os)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    61
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    62
	dsl_dataset_t *ds;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    63
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
    64
	if ((ds = os->os_dsl_dataset) != NULL && ds->ds_dir)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    65
		return (ds->ds_dir->dd_pool);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    66
	else
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
    67
		return (spa_get_dsl(os->os_spa));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    68
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    69
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    70
dsl_dataset_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    71
dmu_objset_ds(objset_t *os)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    72
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
    73
	return (os->os_dsl_dataset);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    74
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    75
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    76
dmu_objset_type_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    77
dmu_objset_type(objset_t *os)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    78
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
    79
	return (os->os_phys->os_type);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    80
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    81
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    82
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    83
dmu_objset_name(objset_t *os, char *buf)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    84
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
    85
	dsl_dataset_name(os->os_dsl_dataset, buf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    86
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    87
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    88
uint64_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    89
dmu_objset_id(objset_t *os)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    90
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
    91
	dsl_dataset_t *ds = os->os_dsl_dataset;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    92
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    93
	return (ds ? ds->ds_object : 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    94
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    95
10310
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
    96
uint64_t
12294
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12178
diff changeset
    97
dmu_objset_syncprop(objset_t *os)
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12178
diff changeset
    98
{
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12178
diff changeset
    99
	return (os->os_sync);
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12178
diff changeset
   100
}
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12178
diff changeset
   101
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12178
diff changeset
   102
uint64_t
10310
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
   103
dmu_objset_logbias(objset_t *os)
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
   104
{
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
   105
	return (os->os_logbias);
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
   106
}
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
   107
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   108
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   109
checksum_changed_cb(void *arg, uint64_t newval)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   110
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   111
	objset_t *os = arg;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   112
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   113
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   114
	 * Inheritance should have been done by now.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   115
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   116
	ASSERT(newval != ZIO_CHECKSUM_INHERIT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   117
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   118
	os->os_checksum = zio_checksum_select(newval, ZIO_CHECKSUM_ON_VALUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   119
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   120
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   121
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   122
compression_changed_cb(void *arg, uint64_t newval)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   123
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   124
	objset_t *os = arg;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   125
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   126
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   127
	 * Inheritance and range checking should have been done by now.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   128
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   129
	ASSERT(newval != ZIO_COMPRESS_INHERIT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   130
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   131
	os->os_compress = zio_compress_select(newval, ZIO_COMPRESS_ON_VALUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   132
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   133
3835
063f0749804a PSARC/2007/121 zfs set copies
ahrens
parents: 3689
diff changeset
   134
static void
063f0749804a PSARC/2007/121 zfs set copies
ahrens
parents: 3689
diff changeset
   135
copies_changed_cb(void *arg, uint64_t newval)
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
	objset_t *os = arg;
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
	/*
063f0749804a PSARC/2007/121 zfs set copies
ahrens
parents: 3689
diff changeset
   140
	 * Inheritance and range checking should have been done by now.
063f0749804a PSARC/2007/121 zfs set copies
ahrens
parents: 3689
diff changeset
   141
	 */
063f0749804a PSARC/2007/121 zfs set copies
ahrens
parents: 3689
diff changeset
   142
	ASSERT(newval > 0);
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   143
	ASSERT(newval <= spa_max_replication(os->os_spa));
3835
063f0749804a PSARC/2007/121 zfs set copies
ahrens
parents: 3689
diff changeset
   144
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   145
	os->os_copies = newval;
3835
063f0749804a PSARC/2007/121 zfs set copies
ahrens
parents: 3689
diff changeset
   146
}
063f0749804a PSARC/2007/121 zfs set copies
ahrens
parents: 3689
diff changeset
   147
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   148
static void
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   149
dedup_changed_cb(void *arg, uint64_t newval)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   150
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   151
	objset_t *os = arg;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   152
	spa_t *spa = os->os_spa;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   153
	enum zio_checksum checksum;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   154
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   155
	/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   156
	 * Inheritance should have been done by now.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   157
	 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   158
	ASSERT(newval != ZIO_CHECKSUM_INHERIT);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   159
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   160
	checksum = zio_checksum_dedup_select(spa, newval, ZIO_CHECKSUM_OFF);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   161
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   162
	os->os_dedup_checksum = checksum & ZIO_CHECKSUM_MASK;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   163
	os->os_dedup_verify = !!(checksum & ZIO_CHECKSUM_VERIFY);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   164
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   165
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   166
static void
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   167
primary_cache_changed_cb(void *arg, uint64_t newval)
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   168
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   169
	objset_t *os = arg;
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   170
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   171
	/*
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   172
	 * Inheritance and range checking should have been done by now.
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   173
	 */
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   174
	ASSERT(newval == ZFS_CACHE_ALL || newval == ZFS_CACHE_NONE ||
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   175
	    newval == ZFS_CACHE_METADATA);
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   176
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   177
	os->os_primary_cache = newval;
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   178
}
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   179
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   180
static void
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   181
secondary_cache_changed_cb(void *arg, uint64_t newval)
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   182
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   183
	objset_t *os = arg;
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   184
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   185
	/*
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   186
	 * Inheritance and range checking should have been done by now.
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   187
	 */
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   188
	ASSERT(newval == ZFS_CACHE_ALL || newval == ZFS_CACHE_NONE ||
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   189
	    newval == ZFS_CACHE_METADATA);
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   190
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   191
	os->os_secondary_cache = newval;
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   192
}
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   193
10310
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
   194
static void
12294
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12178
diff changeset
   195
sync_changed_cb(void *arg, uint64_t newval)
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12178
diff changeset
   196
{
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12178
diff changeset
   197
	objset_t *os = arg;
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12178
diff changeset
   198
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12178
diff changeset
   199
	/*
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12178
diff changeset
   200
	 * Inheritance and range checking should have been done by now.
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12178
diff changeset
   201
	 */
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12178
diff changeset
   202
	ASSERT(newval == ZFS_SYNC_STANDARD || newval == ZFS_SYNC_ALWAYS ||
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12178
diff changeset
   203
	    newval == ZFS_SYNC_DISABLED);
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12178
diff changeset
   204
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12178
diff changeset
   205
	os->os_sync = newval;
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12178
diff changeset
   206
	if (os->os_zil)
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12178
diff changeset
   207
		zil_set_sync(os->os_zil, newval);
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12178
diff changeset
   208
}
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12178
diff changeset
   209
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12178
diff changeset
   210
static void
10310
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
   211
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
   212
{
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
   213
	objset_t *os = arg;
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
   214
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
   215
	ASSERT(newval == ZFS_LOGBIAS_LATENCY ||
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
   216
	    newval == ZFS_LOGBIAS_THROUGHPUT);
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
   217
	os->os_logbias = newval;
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
   218
	if (os->os_zil)
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
   219
		zil_set_logbias(os->os_zil, newval);
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
   220
}
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
   221
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   222
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   223
dmu_objset_byteswap(void *buf, size_t size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   224
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   225
	objset_phys_t *osp = buf;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   226
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   227
	ASSERT(size == OBJSET_OLD_PHYS_SIZE || size == sizeof (objset_phys_t));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   228
	dnode_byteswap(&osp->os_meta_dnode);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   229
	byteswap_uint64_array(&osp->os_zil_header, sizeof (zil_header_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   230
	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
   231
	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
   232
	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
   233
		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
   234
		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
   235
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   236
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   237
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   238
int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   239
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
   240
    objset_t **osp)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   241
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   242
	objset_t *os;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
   243
	int i, err;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   244
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4634
diff changeset
   245
	ASSERT(ds == NULL || MUTEX_HELD(&ds->ds_opening_lock));
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4634
diff changeset
   246
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   247
	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
   248
	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
   249
	os->os_spa = spa;
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   250
	os->os_rootbp = bp;
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   251
	if (!BP_IS_HOLE(os->os_rootbp)) {
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2199
diff changeset
   252
		uint32_t aflags = ARC_WAIT;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   253
		zbookmark_t zb;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   254
		SET_BOOKMARK(&zb, ds ? ds->ds_object : DMU_META_OBJSET,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   255
		    ZB_ROOT_OBJECT, ZB_ROOT_LEVEL, ZB_ROOT_BLKID);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   256
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   257
		if (DMU_OS_IS_L2CACHEABLE(os))
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   258
			aflags |= ARC_L2CACHE;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   259
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   260
		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
   261
		/*
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12294
diff changeset
   262
		 * XXX when bprewrite scrub can change the bp,
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
   263
		 * 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
   264
		 * 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
   265
		 */
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12294
diff changeset
   266
		err = dsl_read_nolock(NULL, spa, os->os_rootbp,
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   267
		    arc_getbuf_func, &os->os_phys_buf,
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2199
diff changeset
   268
		    ZIO_PRIORITY_SYNC_READ, ZIO_FLAG_CANFAIL, &aflags, &zb);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   269
		if (err) {
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   270
			kmem_free(os, sizeof (objset_t));
7294
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7237
diff changeset
   271
			/* convert checksum errors into IO errors */
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7237
diff changeset
   272
			if (err == ECKSUM)
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7237
diff changeset
   273
				err = EIO;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   274
			return (err);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   275
		}
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   276
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   277
		/* 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
   278
		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
   279
		    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
   280
			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
   281
			    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
   282
			    ARC_BUFC_METADATA);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   283
			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
   284
			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
   285
			    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
   286
			(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
   287
			    &os->os_phys_buf);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   288
			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
   289
		}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   290
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   291
		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
   292
		os->os_flags = os->os_phys->os_flags;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   293
	} else {
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   294
		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
   295
		    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
   296
		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
   297
		    &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
   298
		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
   299
		bzero(os->os_phys, size);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   300
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   301
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   302
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   303
	 * Note: the changed_cb will be called once before the register
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   304
	 * func returns, thus changing the checksum/compression from the
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   305
	 * default (fletcher2/off).  Snapshots don't need to know about
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   306
	 * checksum/compression/copies.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   307
	 */
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   308
	if (ds) {
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   309
		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
   310
		    primary_cache_changed_cb, os);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   311
		if (err == 0)
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   312
			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
   313
			    secondary_cache_changed_cb, os);
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   314
		if (!dsl_dataset_is_snapshot(ds)) {
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   315
			if (err == 0)
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   316
				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
   317
				    checksum_changed_cb, os);
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   318
			if (err == 0)
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   319
				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
   320
				    compression_changed_cb, os);
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   321
			if (err == 0)
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   322
				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
   323
				    copies_changed_cb, os);
10310
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
   324
			if (err == 0)
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   325
				err = dsl_prop_register(ds, "dedup",
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   326
				    dedup_changed_cb, os);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   327
			if (err == 0)
10310
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
   328
				err = dsl_prop_register(ds, "logbias",
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
   329
				    logbias_changed_cb, os);
12294
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12178
diff changeset
   330
			if (err == 0)
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12178
diff changeset
   331
				err = dsl_prop_register(ds, "sync",
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12178
diff changeset
   332
				    sync_changed_cb, os);
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   333
		}
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   334
		if (err) {
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   335
			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
   336
			    &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
   337
			kmem_free(os, sizeof (objset_t));
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   338
			return (err);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   339
		}
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
   340
	} else if (ds == NULL) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   341
		/* 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
   342
		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
   343
		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
   344
		os->os_copies = spa_max_replication(spa);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   345
		os->os_dedup_checksum = ZIO_CHECKSUM_OFF;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   346
		os->os_dedup_verify = 0;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   347
		os->os_logbias = 0;
12294
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12178
diff changeset
   348
		os->os_sync = 0;
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   349
		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
   350
		os->os_secondary_cache = ZFS_CACHE_ALL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   351
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   352
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   353
	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
   354
	os->os_zil = zil_alloc(os, &os->os_zil_header);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   355
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   356
	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
   357
		list_create(&os->os_dirty_dnodes[i], sizeof (dnode_t),
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   358
		    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
   359
		list_create(&os->os_free_dnodes[i], sizeof (dnode_t),
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   360
		    offsetof(dnode_t, dn_dirty_link[i]));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   361
	}
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   362
	list_create(&os->os_dnodes, sizeof (dnode_t),
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   363
	    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
   364
	list_create(&os->os_downgraded_dbufs, sizeof (dmu_buf_impl_t),
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   365
	    offsetof(dmu_buf_impl_t, db_link));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   366
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   367
	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
   368
	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
   369
	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
   370
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   371
	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
   372
	    &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
   373
	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
   374
		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
   375
		    &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
   376
		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
   377
		    &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
   378
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   379
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4634
diff changeset
   380
	/*
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4634
diff changeset
   381
	 * We should be the only thread trying to do this because we
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4634
diff changeset
   382
	 * have ds_opening_lock
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4634
diff changeset
   383
	 */
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4634
diff changeset
   384
	if (ds) {
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   385
		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
   386
		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
   387
		ds->ds_objset = os;
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   388
		mutex_exit(&ds->ds_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   389
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   390
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   391
	*osp = os;
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5329
diff changeset
   392
	return (0);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5329
diff changeset
   393
}
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5329
diff changeset
   394
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5329
diff changeset
   395
int
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   396
dmu_objset_from_ds(dsl_dataset_t *ds, objset_t **osp)
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5329
diff changeset
   397
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   398
	int err = 0;
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   399
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   400
	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
   401
	*osp = ds->ds_objset;
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   402
	if (*osp == NULL) {
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   403
		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
   404
		    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
   405
	}
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   406
	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
   407
	return (err);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   408
}
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
/* called from zpl */
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   411
int
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   412
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
   413
{
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   414
	dsl_dataset_t *ds;
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5329
diff changeset
   415
	int err;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5329
diff changeset
   416
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   417
	err = dsl_dataset_hold(name, tag, &ds);
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5329
diff changeset
   418
	if (err)
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   419
		return (err);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   420
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   421
	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
   422
	if (err)
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   423
		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
   424
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5329
diff changeset
   425
	return (err);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5329
diff changeset
   426
}
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5329
diff changeset
   427
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   428
/* called from zpl */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   429
int
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   430
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
   431
    boolean_t readonly, void *tag, objset_t **osp)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   432
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   433
	dsl_dataset_t *ds;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   434
	int err;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   435
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   436
	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
   437
	if (err)
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   438
		return (err);
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5329
diff changeset
   439
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   440
	err = dmu_objset_from_ds(ds, osp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   441
	if (err) {
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   442
		dsl_dataset_disown(ds, tag);
10588
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10407
diff changeset
   443
	} else if (type != DMU_OST_ANY && type != (*osp)->os_phys->os_type) {
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   444
		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
   445
		return (EINVAL);
10588
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10407
diff changeset
   446
	} else if (!readonly && dsl_dataset_is_snapshot(ds)) {
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10407
diff changeset
   447
		dmu_objset_disown(*osp, tag);
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10407
diff changeset
   448
		return (EROFS);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   449
	}
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5329
diff changeset
   450
	return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   451
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   452
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   453
void
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   454
dmu_objset_rele(objset_t *os, void *tag)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   455
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   456
	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
   457
}
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6492
diff changeset
   458
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   459
void
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   460
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
   461
{
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   462
	dsl_dataset_disown(os->os_dsl_dataset, tag);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   463
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   464
1646
b4e43ae19fff 6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents: 1596
diff changeset
   465
int
4944
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4935
diff changeset
   466
dmu_objset_evict_dbufs(objset_t *os)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   467
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   468
	dnode_t *dn;
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
   469
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   470
	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
   471
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
   472
	/* 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
   473
	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
   474
	list_insert_tail(&os->os_dnodes, os->os_meta_dnode);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   475
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   476
	/*
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
   477
	 * 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
   478
	 * 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
   479
	 * 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
   480
	 * skip.
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   481
	 */
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   482
	for (dn = list_head(&os->os_dnodes);
4944
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4935
diff changeset
   483
	    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
   484
	    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
   485
		continue;
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
   486
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
   487
	while (dn) {
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
   488
		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
   489
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
   490
		do {
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   491
			next_dn = list_next(&os->os_dnodes, next_dn);
4944
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4935
diff changeset
   492
		} 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
   493
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   494
		mutex_exit(&os->os_lock);
4944
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4935
diff changeset
   495
		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
   496
		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
   497
		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
   498
		dn = next_dn;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   499
	}
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   500
	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
   501
	return (list_head(&os->os_dnodes) != os->os_meta_dnode);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   502
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   503
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   504
void
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   505
dmu_objset_evict(objset_t *os)
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
	dsl_dataset_t *ds = os->os_dsl_dataset;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   508
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   509
	for (int t = 0; t < TXG_SIZE; t++)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   510
		ASSERT(!dmu_objset_is_dirty(os, t));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   511
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   512
	if (ds) {
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   513
		if (!dsl_dataset_is_snapshot(ds)) {
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   514
			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
   515
			    checksum_changed_cb, os));
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   516
			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
   517
			    compression_changed_cb, os));
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   518
			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
   519
			    copies_changed_cb, os));
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   520
			VERIFY(0 == dsl_prop_unregister(ds, "dedup",
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   521
			    dedup_changed_cb, os));
10310
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
   522
			VERIFY(0 == dsl_prop_unregister(ds, "logbias",
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
   523
			    logbias_changed_cb, os));
12294
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12178
diff changeset
   524
			VERIFY(0 == dsl_prop_unregister(ds, "sync",
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12178
diff changeset
   525
			    sync_changed_cb, os));
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   526
		}
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   527
		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
   528
		    primary_cache_changed_cb, os));
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   529
		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
   530
		    secondary_cache_changed_cb, os));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   531
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   532
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
   533
	if (os->os_sa)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
   534
		sa_tear_down(os);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
   535
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   536
	/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   537
	 * We should need only a single pass over the dnode list, since
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   538
	 * nothing can be added to the list at this point.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   539
	 */
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   540
	(void) dmu_objset_evict_dbufs(os);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   541
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   542
	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
   543
	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
   544
		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
   545
		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
   546
	}
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   547
	zil_free(os->os_zil);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   548
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   549
	ASSERT3P(list_head(&os->os_dnodes), ==, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   550
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   551
	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
   552
	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
   553
	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
   554
	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
   555
	kmem_free(os, sizeof (objset_t));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   556
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   557
10373
bcf97ee54990 6395956 snapshot dir needs real c/mtime
Chris Kirby <chris.kirby@sun.com>
parents: 10310
diff changeset
   558
timestruc_t
bcf97ee54990 6395956 snapshot dir needs real c/mtime
Chris Kirby <chris.kirby@sun.com>
parents: 10310
diff changeset
   559
dmu_objset_snap_cmtime(objset_t *os)
bcf97ee54990 6395956 snapshot dir needs real c/mtime
Chris Kirby <chris.kirby@sun.com>
parents: 10310
diff changeset
   560
{
bcf97ee54990 6395956 snapshot dir needs real c/mtime
Chris Kirby <chris.kirby@sun.com>
parents: 10310
diff changeset
   561
	return (dsl_dir_snap_cmtime(os->os_dsl_dataset->ds_dir));
bcf97ee54990 6395956 snapshot dir needs real c/mtime
Chris Kirby <chris.kirby@sun.com>
parents: 10310
diff changeset
   562
}
bcf97ee54990 6395956 snapshot dir needs real c/mtime
Chris Kirby <chris.kirby@sun.com>
parents: 10310
diff changeset
   563
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   564
/* 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
   565
objset_t *
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   566
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
   567
    dmu_objset_type_t type, dmu_tx_t *tx)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   568
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   569
	objset_t *os;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   570
	dnode_t *mdn;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   571
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   572
	ASSERT(dmu_tx_is_syncing(tx));
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4634
diff changeset
   573
	if (ds)
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4634
diff changeset
   574
		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
   575
	VERIFY(0 == dmu_objset_open_impl(spa, ds, bp, &os));
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4634
diff changeset
   576
	if (ds)
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4634
diff changeset
   577
		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
   578
	mdn = os->os_meta_dnode;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   579
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   580
	dnode_allocate(mdn, DMU_OT_DNODE, 1 << DNODE_BLOCK_SHIFT,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   581
	    DN_MAX_INDBLKSHIFT, DMU_OT_NONE, 0, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   582
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   583
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   584
	 * We don't want to have to increase the meta-dnode's nlevels
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   585
	 * later, because then we could do it in quescing context while
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   586
	 * we are also accessing it in open context.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   587
	 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   588
	 * This precaution is not necessary for the MOS (ds == NULL),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   589
	 * because the MOS is only updated in syncing context.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   590
	 * This is most fortunate: the MOS is the only objset that
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   591
	 * needs to be synced multiple times as spa_sync() iterates
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   592
	 * to convergence, so minimizing its dn_nlevels matters.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   593
	 */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   594
	if (ds != NULL) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   595
		int levels = 1;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   596
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   597
		/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   598
		 * Determine the number of levels necessary for the meta-dnode
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   599
		 * to contain DN_MAX_OBJECT dnodes.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   600
		 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   601
		while ((uint64_t)mdn->dn_nblkptr << (mdn->dn_datablkshift +
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   602
		    (levels - 1) * (mdn->dn_indblkshift - SPA_BLKPTRSHIFT)) <
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   603
		    DN_MAX_OBJECT * sizeof (dnode_phys_t))
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   604
			levels++;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   605
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   606
		mdn->dn_next_nlevels[tx->tx_txg & TXG_MASK] =
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   607
		    mdn->dn_nlevels = levels;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   608
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   609
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   610
	ASSERT(type != DMU_OST_NONE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   611
	ASSERT(type != DMU_OST_ANY);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   612
	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
   613
	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
   614
	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
   615
		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
   616
		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
   617
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   618
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   619
	dsl_dataset_dirty(ds, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
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
	return (os);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   622
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   623
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   624
struct oscarg {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3978
diff changeset
   625
	void (*userfunc)(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   626
	void *userarg;
10272
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   627
	dsl_dataset_t *clone_origin;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   628
	const char *lastname;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   629
	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
   630
	uint64_t flags;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12294
diff changeset
   631
	cred_t *cr;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   632
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   633
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3978
diff changeset
   634
/*ARGSUSED*/
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   635
static int
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   636
dmu_objset_create_check(void *arg1, void *arg2, dmu_tx_t *tx)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   637
{
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   638
	dsl_dir_t *dd = arg1;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   639
	struct oscarg *oa = arg2;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   640
	objset_t *mos = dd->dd_pool->dp_meta_objset;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   641
	int err;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   642
	uint64_t ddobj;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   643
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   644
	err = zap_lookup(mos, dd->dd_phys->dd_child_dir_zapobj,
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   645
	    oa->lastname, sizeof (uint64_t), 1, &ddobj);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   646
	if (err != ENOENT)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   647
		return (err ? err : EEXIST);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   648
10272
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   649
	if (oa->clone_origin != NULL) {
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   650
		/* 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
   651
		if (oa->clone_origin->ds_dir->dd_pool != dd->dd_pool)
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   652
			return (EXDEV);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   653
10272
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   654
		/* 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
   655
		if (!dsl_dataset_is_snapshot(oa->clone_origin))
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   656
			return (EINVAL);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   657
	}
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3978
diff changeset
   658
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   659
	return (0);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   660
}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   661
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   662
static void
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12294
diff changeset
   663
dmu_objset_create_sync(void *arg1, void *arg2, dmu_tx_t *tx)
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   664
{
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   665
	dsl_dir_t *dd = arg1;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   666
	struct oscarg *oa = arg2;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   667
	uint64_t dsobj;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   668
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   669
	ASSERT(dmu_tx_is_syncing(tx));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   670
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   671
	dsobj = dsl_dataset_create_sync(dd, oa->lastname,
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12294
diff changeset
   672
	    oa->clone_origin, oa->flags, oa->cr, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   673
10272
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   674
	if (oa->clone_origin == NULL) {
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   675
		dsl_dataset_t *ds;
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   676
		blkptr_t *bp;
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   677
		objset_t *os;
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
		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
   680
		    FTAG, &ds));
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   681
		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
   682
		ASSERT(BP_IS_HOLE(bp));
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   683
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   684
		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
   685
		    ds, bp, oa->type, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   686
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   687
		if (oa->userfunc)
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12294
diff changeset
   688
			oa->userfunc(os, oa->userarg, oa->cr, tx);
10272
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   689
		dsl_dataset_rele(ds, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   690
	}
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3978
diff changeset
   691
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12294
diff changeset
   692
	spa_history_log_internal(LOG_DS_CREATE, dd->dd_pool->dp_spa,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12294
diff changeset
   693
	    tx, "dataset = %llu", dsobj);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   694
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   695
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   696
int
10272
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   697
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
   698
    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
   699
{
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   700
	dsl_dir_t *pdd;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   701
	const char *tail;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   702
	int err = 0;
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   703
	struct oscarg oa = { 0 };
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   704
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   705
	ASSERT(strchr(name, '@') == NULL);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   706
	err = dsl_dir_open(name, FTAG, &pdd, &tail);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   707
	if (err)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   708
		return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   709
	if (tail == NULL) {
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   710
		dsl_dir_close(pdd, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   711
		return (EEXIST);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   712
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   713
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   714
	oa.userfunc = func;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   715
	oa.userarg = arg;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   716
	oa.lastname = tail;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   717
	oa.type = type;
6492
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6174
diff changeset
   718
	oa.flags = flags;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12294
diff changeset
   719
	oa.cr = CRED();
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3978
diff changeset
   720
10272
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   721
	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
   722
	    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
   723
	dsl_dir_close(pdd, FTAG);
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   724
	return (err);
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   725
}
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   726
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   727
int
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   728
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
   729
{
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   730
	dsl_dir_t *pdd;
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   731
	const char *tail;
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   732
	int err = 0;
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   733
	struct oscarg oa = { 0 };
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   734
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   735
	ASSERT(strchr(name, '@') == NULL);
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   736
	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
   737
	if (err)
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   738
		return (err);
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   739
	if (tail == NULL) {
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   740
		dsl_dir_close(pdd, FTAG);
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   741
		return (EEXIST);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   742
	}
10272
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   743
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   744
	oa.lastname = tail;
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   745
	oa.clone_origin = clone_origin;
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   746
	oa.flags = flags;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12294
diff changeset
   747
	oa.cr = CRED();
10272
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   748
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   749
	err = dsl_sync_task_do(pdd->dd_pool, dmu_objset_create_check,
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   750
	    dmu_objset_create_sync, pdd, &oa, 5);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   751
	dsl_dir_close(pdd, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   752
	return (err);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   753
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   754
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   755
int
10242
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 9951
diff changeset
   756
dmu_objset_destroy(const char *name, boolean_t defer)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   757
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   758
	dsl_dataset_t *ds;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   759
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   760
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   761
	/*
10272
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   762
	 * 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
   763
	 * 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
   764
	 * 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
   765
	 * 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
   766
	 * to call into it here.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   767
	 */
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   768
	error = dsl_dataset_own(name, B_TRUE, FTAG, &ds);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   769
	if (error == 0) {
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   770
		objset_t *os;
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   771
		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
   772
			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
   773
		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
   774
		/* dsl_dataset_destroy() closes the ds. */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   775
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   776
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5329
diff changeset
   777
	return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   778
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   779
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   780
struct snaparg {
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   781
	dsl_sync_task_group_t *dstg;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   782
	char *snapname;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   783
	char failed[MAXPATHLEN];
11620
ebeec53e6212 6878304 can't create snapshot due to temporary '%rollback' dataset
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11209
diff changeset
   784
	boolean_t recursive;
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
   785
	nvlist_t *props;
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5329
diff changeset
   786
};
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5329
diff changeset
   787
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
   788
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
   789
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
   790
{
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
   791
	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
   792
	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
   793
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
	/* 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
   795
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   796
	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
   797
	    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
   798
}
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
   799
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
   800
static void
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12294
diff changeset
   801
snapshot_sync(void *arg1, void *arg2, dmu_tx_t *tx)
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
   802
{
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
   803
	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
   804
	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
   805
	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
   806
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12294
diff changeset
   807
	dsl_dataset_snapshot_sync(ds, sn->snapname, tx);
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
   808
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10922
diff changeset
   809
	if (sn->props) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10922
diff changeset
   810
		dsl_props_arg_t pa;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10922
diff changeset
   811
		pa.pa_props = sn->props;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10922
diff changeset
   812
		pa.pa_source = ZPROP_SRC_LOCAL;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12294
diff changeset
   813
		dsl_props_set_sync(ds->ds_prev, &pa, tx);
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10922
diff changeset
   814
	}
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
   815
}
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   816
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   817
static int
11209
462283cb4096 6905188 panic: kernel heap corruption when doing "zfs rename -r"
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11165
diff changeset
   818
dmu_objset_snapshot_one(const char *name, void *arg)
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   819
{
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   820
	struct snaparg *sn = arg;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   821
	objset_t *os;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   822
	int err;
11620
ebeec53e6212 6878304 can't create snapshot due to temporary '%rollback' dataset
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11209
diff changeset
   823
	char *cp;
ebeec53e6212 6878304 can't create snapshot due to temporary '%rollback' dataset
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11209
diff changeset
   824
ebeec53e6212 6878304 can't create snapshot due to temporary '%rollback' dataset
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11209
diff changeset
   825
	/*
ebeec53e6212 6878304 can't create snapshot due to temporary '%rollback' dataset
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11209
diff changeset
   826
	 * If the objset starts with a '%', then ignore it unless it was
ebeec53e6212 6878304 can't create snapshot due to temporary '%rollback' dataset
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11209
diff changeset
   827
	 * explicitly named (ie, not recursive).  These hidden datasets
ebeec53e6212 6878304 can't create snapshot due to temporary '%rollback' dataset
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11209
diff changeset
   828
	 * are always inconsistent, and by not opening them here, we can
ebeec53e6212 6878304 can't create snapshot due to temporary '%rollback' dataset
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11209
diff changeset
   829
	 * avoid a race with dsl_dir_destroy_check().
ebeec53e6212 6878304 can't create snapshot due to temporary '%rollback' dataset
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11209
diff changeset
   830
	 */
ebeec53e6212 6878304 can't create snapshot due to temporary '%rollback' dataset
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11209
diff changeset
   831
	cp = strrchr(name, '/');
ebeec53e6212 6878304 can't create snapshot due to temporary '%rollback' dataset
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11209
diff changeset
   832
	if (cp && cp[1] == '%' && sn->recursive)
ebeec53e6212 6878304 can't create snapshot due to temporary '%rollback' dataset
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11209
diff changeset
   833
		return (0);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   834
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   835
	(void) strcpy(sn->failed, name);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   836
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3978
diff changeset
   837
	/*
11620
ebeec53e6212 6878304 can't create snapshot due to temporary '%rollback' dataset
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11209
diff changeset
   838
	 * Check permissions if we are doing a recursive snapshot.  The
ebeec53e6212 6878304 can't create snapshot due to temporary '%rollback' dataset
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11209
diff changeset
   839
	 * permission checks for the starting dataset have already been
ebeec53e6212 6878304 can't create snapshot due to temporary '%rollback' dataset
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11209
diff changeset
   840
	 * performed in zfs_secpolicy_snapshot()
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3978
diff changeset
   841
	 */
11620
ebeec53e6212 6878304 can't create snapshot due to temporary '%rollback' dataset
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11209
diff changeset
   842
	if (sn->recursive && (err = zfs_secpolicy_snapshot_perms(name, CRED())))
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3978
diff changeset
   843
		return (err);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3978
diff changeset
   844
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   845
	err = dmu_objset_hold(name, sn, &os);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   846
	if (err != 0)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   847
		return (err);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   848
11620
ebeec53e6212 6878304 can't create snapshot due to temporary '%rollback' dataset
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11209
diff changeset
   849
	/*
ebeec53e6212 6878304 can't create snapshot due to temporary '%rollback' dataset
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11209
diff changeset
   850
	 * If the objset is in an inconsistent state (eg, in the process
ebeec53e6212 6878304 can't create snapshot due to temporary '%rollback' dataset
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11209
diff changeset
   851
	 * of being destroyed), don't snapshot it.  As with %hidden
ebeec53e6212 6878304 can't create snapshot due to temporary '%rollback' dataset
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11209
diff changeset
   852
	 * datasets, we return EBUSY if this name was explicitly
ebeec53e6212 6878304 can't create snapshot due to temporary '%rollback' dataset
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11209
diff changeset
   853
	 * requested (ie, not recursive), and otherwise ignore it.
ebeec53e6212 6878304 can't create snapshot due to temporary '%rollback' dataset
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11209
diff changeset
   854
	 */
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   855
	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
   856
		dmu_objset_rele(os, sn);
11620
ebeec53e6212 6878304 can't create snapshot due to temporary '%rollback' dataset
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11209
diff changeset
   857
		return (sn->recursive ? 0 : EBUSY);
3637
526d8412c163 6402600 administrative actions while doing 'zfs recv' or 'zfs destroy' can cause confusing situation
rm160521
parents: 3547
diff changeset
   858
	}
526d8412c163 6402600 administrative actions while doing 'zfs recv' or 'zfs destroy' can cause confusing situation
rm160521
parents: 3547
diff changeset
   859
526d8412c163 6402600 administrative actions while doing 'zfs recv' or 'zfs destroy' can cause confusing situation
rm160521
parents: 3547
diff changeset
   860
	/*
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   861
	 * 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
   862
	 * so that we snapshot those changes.  zil_suspend does this as
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   863
	 * a side effect.
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   864
	 */
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   865
	err = zil_suspend(dmu_objset_zil(os));
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   866
	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
   867
		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
   868
		    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
   869
	} else {
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   870
		dmu_objset_rele(os, sn);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   871
	}
3637
526d8412c163 6402600 administrative actions while doing 'zfs recv' or 'zfs destroy' can cause confusing situation
rm160521
parents: 3547
diff changeset
   872
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   873
	return (err);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   874
}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   875
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   876
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
   877
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
   878
    nvlist_t *props, boolean_t recursive)
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   879
{
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   880
	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
   881
	struct snaparg sn;
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   882
	spa_t *spa;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   883
	int err;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   884
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   885
	(void) strcpy(sn.failed, fsname);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   886
4603
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4543
diff changeset
   887
	err = spa_open(fsname, &spa, FTAG);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   888
	if (err)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   889
		return (err);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   890
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   891
	sn.dstg = dsl_sync_task_group_create(spa_get_dsl(spa));
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   892
	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
   893
	sn.props = props;
11620
ebeec53e6212 6878304 can't create snapshot due to temporary '%rollback' dataset
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11209
diff changeset
   894
	sn.recursive = recursive;
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   895
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2391
diff changeset
   896
	if (recursive) {
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2391
diff changeset
   897
		err = dmu_objset_find(fsname,
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2391
diff changeset
   898
		    dmu_objset_snapshot_one, &sn, DS_FIND_CHILDREN);
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2391
diff changeset
   899
	} else {
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   900
		err = dmu_objset_snapshot_one(fsname, &sn);
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2391
diff changeset
   901
	}
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   902
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
   903
	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
   904
		err = dsl_sync_task_group_wait(sn.dstg);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   905
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   906
	for (dst = list_head(&sn.dstg->dstg_tasks); dst;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   907
	    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
   908
		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
   909
		dsl_dataset_t *ds = os->os_dsl_dataset;
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   910
		if (dst->dst_err)
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5329
diff changeset
   911
			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
   912
		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
   913
		dmu_objset_rele(os, &sn);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   914
	}
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5329
diff changeset
   915
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   916
	if (err)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   917
		(void) strcpy(fsname, sn.failed);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   918
	dsl_sync_task_group_destroy(sn.dstg);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   919
	spa_close(spa, FTAG);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   920
	return (err);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   921
}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   922
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   923
static void
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   924
dmu_objset_sync_dnodes(list_t *list, list_t *newlist, dmu_tx_t *tx)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   925
{
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   926
	dnode_t *dn;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   927
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   928
	while (dn = list_head(list)) {
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   929
		ASSERT(dn->dn_object != DMU_META_DNODE_OBJECT);
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   930
		ASSERT(dn->dn_dbuf->db_data_pending);
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   931
		/*
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   932
		 * 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
   933
		 * 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
   934
		 */
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   935
		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
   936
		ASSERT(dn->dn_zio);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   937
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   938
		ASSERT3U(dn->dn_nlevels, <=, DN_MAX_LEVELS);
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   939
		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
   940
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   941
		if (newlist) {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   942
			(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
   943
			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
   944
		}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   945
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   946
		dnode_sync(dn, tx);
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   947
	}
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   948
}
2981
b80f5da0b8ed 6485955 need more dtrace probes
ahrens
parents: 2885
diff changeset
   949
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   950
/* ARGSUSED */
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   951
static void
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   952
dmu_objset_write_ready(zio_t *zio, arc_buf_t *abuf, void *arg)
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   953
{
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
   954
	blkptr_t *bp = zio->io_bp;
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   955
	objset_t *os = arg;
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   956
	dnode_phys_t *dnp = &os->os_phys->os_meta_dnode;
2981
b80f5da0b8ed 6485955 need more dtrace probes
ahrens
parents: 2885
diff changeset
   957
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
   958
	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
   959
	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
   960
	ASSERT(BP_GET_LEVEL(bp) == 0);
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
   961
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   962
	/*
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   963
	 * 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
   964
	 * 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
   965
	 * 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
   966
	 * dnode and user/group accounting objects).
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   967
	 */
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   968
	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
   969
	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
   970
		bp->blk_fill += dnp->dn_blkptr[i].blk_fill;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   971
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   972
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   973
/* ARGSUSED */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   974
static void
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   975
dmu_objset_write_done(zio_t *zio, arc_buf_t *abuf, void *arg)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   976
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   977
	blkptr_t *bp = zio->io_bp;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   978
	blkptr_t *bp_orig = &zio->io_bp_orig;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   979
	objset_t *os = arg;
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
   980
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
   981
	if (zio->io_flags & ZIO_FLAG_IO_REWRITE) {
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   982
		ASSERT(BP_EQUAL(bp, bp_orig));
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
   983
	} else {
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   984
		dsl_dataset_t *ds = os->os_dsl_dataset;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   985
		dmu_tx_t *tx = os->os_synctx;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   986
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   987
		(void) dsl_dataset_block_kill(ds, bp_orig, tx, B_TRUE);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   988
		dsl_dataset_block_born(ds, bp, tx);
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
   989
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   990
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   991
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   992
/* called from dsl */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   993
void
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   994
dmu_objset_sync(objset_t *os, zio_t *pio, dmu_tx_t *tx)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   995
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   996
	int txgoff;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   997
	zbookmark_t zb;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
   998
	zio_prop_t zp;
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   999
	zio_t *zio;
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
  1000
	list_t *list;
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1001
	list_t *newlist = NULL;
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
  1002
	dbuf_dirty_record_t *dr;
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
  1003
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
  1004
	dprintf_ds(os->os_dsl_dataset, "txg=%llu\n", tx->tx_txg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1005
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1006
	ASSERT(dmu_tx_is_syncing(tx));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1007
	/* XXX the write_done callback should really give us the tx... */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1008
	os->os_synctx = tx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1009
3882
f58e2c1a879e 6520462 assertion failed in zio_write_compress
ahrens
parents: 3835
diff changeset
  1010
	if (os->os_dsl_dataset == NULL) {
f58e2c1a879e 6520462 assertion failed in zio_write_compress
ahrens
parents: 3835
diff changeset
  1011
		/*
f58e2c1a879e 6520462 assertion failed in zio_write_compress
ahrens
parents: 3835
diff changeset
  1012
		 * This is the MOS.  If we have upgraded,
f58e2c1a879e 6520462 assertion failed in zio_write_compress
ahrens
parents: 3835
diff changeset
  1013
		 * spa_max_replication() could change, so reset
f58e2c1a879e 6520462 assertion failed in zio_write_compress
ahrens
parents: 3835
diff changeset
  1014
		 * os_copies here.
f58e2c1a879e 6520462 assertion failed in zio_write_compress
ahrens
parents: 3835
diff changeset
  1015
		 */
f58e2c1a879e 6520462 assertion failed in zio_write_compress
ahrens
parents: 3835
diff changeset
  1016
		os->os_copies = spa_max_replication(os->os_spa);
f58e2c1a879e 6520462 assertion failed in zio_write_compress
ahrens
parents: 3835
diff changeset
  1017
	}
f58e2c1a879e 6520462 assertion failed in zio_write_compress
ahrens
parents: 3835
diff changeset
  1018
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
  1019
	/*
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
  1020
	 * Create the root block IO
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
  1021
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
  1022
	SET_BOOKMARK(&zb, os->os_dsl_dataset ?
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
  1023
	    os->os_dsl_dataset->ds_object : DMU_META_OBJSET,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
  1024
	    ZB_ROOT_OBJECT, ZB_ROOT_LEVEL, ZB_ROOT_BLKID);
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12294
diff changeset
  1025
	VERIFY3U(0, ==, arc_release_bp(os->os_phys_buf, &os->os_phys_buf,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12294
diff changeset
  1026
	    os->os_rootbp, os->os_spa, &zb));
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
  1027
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
  1028
	dmu_write_policy(os, NULL, 0, 0, &zp);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
  1029
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
  1030
	zio = arc_write(pio, os->os_spa, tx->tx_txg,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
  1031
	    os->os_rootbp, os->os_phys_buf, DMU_OS_IS_L2CACHEABLE(os), &zp,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
  1032
	    dmu_objset_write_ready, dmu_objset_write_done, os,
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
  1033
	    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
  1034
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
  1035
	/*
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1036
	 * 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
  1037
	 */
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
  1038
	os->os_meta_dnode->dn_zio = zio;
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
  1039
	dnode_sync(os->os_meta_dnode, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1040
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1041
	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
  1042
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1043
	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
  1044
	    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
  1045
		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
  1046
		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
  1047
		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
  1048
		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
  1049
	}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1050
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1051
	txgoff = tx->tx_txg & TXG_MASK;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1052
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1053
	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
  1054
		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
  1055
		/*
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1056
		 * 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
  1057
		 * 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
  1058
		 */
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1059
		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
  1060
		    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
  1061
	}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1062
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1063
	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
  1064
	dmu_objset_sync_dnodes(&os->os_dirty_dnodes[txgoff], newlist, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1065
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
  1066
	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
  1067
	while (dr = list_head(list)) {
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
  1068
		ASSERT(dr->dr_dbuf->db_level == 0);
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
  1069
		list_remove(list, dr);
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
  1070
		if (dr->dr_zio)
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
  1071
			zio_nowait(dr->dr_zio);
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
  1072
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1073
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1074
	 * Free intent log blocks up to this tx.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1075
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1076
	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
  1077
	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
  1078
	zio_nowait(zio);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1079
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1080
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
  1081
boolean_t
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
  1082
dmu_objset_is_dirty(objset_t *os, uint64_t txg)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
  1083
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
  1084
	return (!list_is_empty(&os->os_dirty_dnodes[txg & TXG_MASK]) ||
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
  1085
	    !list_is_empty(&os->os_free_dnodes[txg & TXG_MASK]));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
  1086
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
  1087
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12294
diff changeset
  1088
objset_used_cb_t *used_cbs[DMU_OST_NUMTYPES];
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1089
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1090
void
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1091
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
  1092
{
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1093
	used_cbs[ost] = cb;
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
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1096
boolean_t
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1097
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
  1098
{
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1099
	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
  1100
	    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
  1101
	    os->os_userused_dnode);
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
10407
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10373
diff changeset
  1104
static void
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1105
do_userquota_update(objset_t *os, uint64_t used, uint64_t flags,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1106
    uint64_t user, uint64_t group, boolean_t subtract, dmu_tx_t *tx)
10407
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10373
diff changeset
  1107
{
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1108
	if ((flags & DNODE_FLAG_USERUSED_ACCOUNTED)) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1109
		int64_t delta = DNODE_SIZE + used;
10407
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10373
diff changeset
  1110
		if (subtract)
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10373
diff changeset
  1111
			delta = -delta;
10801
e0bf032e8673 6822816 assertion failed: zap_remove_int(ds_next_clones_obj) returns ENOENT
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10588
diff changeset
  1112
		VERIFY3U(0, ==, zap_increment_int(os, DMU_USERUSED_OBJECT,
10407
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10373
diff changeset
  1113
		    user, delta, tx));
10801
e0bf032e8673 6822816 assertion failed: zap_remove_int(ds_next_clones_obj) returns ENOENT
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10588
diff changeset
  1114
		VERIFY3U(0, ==, zap_increment_int(os, DMU_GROUPUSED_OBJECT,
10407
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10373
diff changeset
  1115
		    group, delta, tx));
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10373
diff changeset
  1116
	}
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10373
diff changeset
  1117
}
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10373
diff changeset
  1118
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1119
void
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1120
dmu_objset_do_userquota_updates(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
  1121
{
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1122
	dnode_t *dn;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1123
	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
  1124
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1125
	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
  1126
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1127
	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
  1128
		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
  1129
		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
  1130
		    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
  1131
		    DNODE_FLAG_USERUSED_ACCOUNTED);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1132
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1133
		/* 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
  1134
		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
  1135
			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
  1136
			    DMU_USERUSED_OBJECT,
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1137
			    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
  1138
			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
  1139
			    DMU_GROUPUSED_OBJECT,
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1140
			    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
  1141
		}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1142
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1143
		/*
10407
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10373
diff changeset
  1144
		 * We intentionally modify the zap object even if the
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1145
		 * net delta is zero.  Otherwise
10407
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10373
diff changeset
  1146
		 * the block of the zap obj could be shared between
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10373
diff changeset
  1147
		 * datasets but need to be different between them after
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10373
diff changeset
  1148
		 * a bprewrite.
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1149
		 */
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1150
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1151
		mutex_enter(&dn->dn_mtx);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1152
		ASSERT(dn->dn_id_flags);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1153
		if (dn->dn_id_flags & DN_ID_OLD_EXIST)  {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1154
			do_userquota_update(os, dn->dn_oldused, dn->dn_oldflags,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1155
			    dn->dn_olduid, dn->dn_oldgid, B_TRUE, tx);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1156
		}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1157
		if (dn->dn_id_flags & DN_ID_NEW_EXIST) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1158
			do_userquota_update(os, DN_USED_BYTES(dn->dn_phys),
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1159
			    dn->dn_phys->dn_flags,  dn->dn_newuid,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1160
			    dn->dn_newgid, B_FALSE, tx);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1161
		}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1162
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1163
		dn->dn_oldused = 0;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1164
		dn->dn_oldflags = 0;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1165
		if (dn->dn_id_flags & DN_ID_NEW_EXIST) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1166
			dn->dn_olduid = dn->dn_newuid;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1167
			dn->dn_oldgid = dn->dn_newgid;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1168
			dn->dn_id_flags |= DN_ID_OLD_EXIST;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1169
			if (dn->dn_bonuslen == 0)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1170
				dn->dn_id_flags |= DN_ID_CHKED_SPILL;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1171
			else
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1172
				dn->dn_id_flags |= DN_ID_CHKED_BONUS;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1173
		}
12432
222dd376dd6c 6952522 elpaso panics: assertion failed: refcount_is_zero(&dn->dn_holds), file: ../../common/fs/zfs/dnode.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12296
diff changeset
  1174
		dn->dn_id_flags &= ~(DN_ID_NEW_EXIST);
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1175
		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
  1176
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1177
		list_remove(list, dn);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1178
		dnode_rele(dn, list);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1179
	}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1180
}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1181
12178
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1182
/*
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1183
 * Returns a pointer to data to find uid/gid from
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1184
 *
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1185
 * If a dirty record for transaction group that is syncing can't
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1186
 * be found then NULL is returned.  In the NULL case it is assumed
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1187
 * the uid/gid aren't changing.
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1188
 */
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1189
static void *
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1190
dmu_objset_userquota_find_data(dmu_buf_impl_t *db, dmu_tx_t *tx)
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1191
{
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1192
	dbuf_dirty_record_t *dr, **drp;
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1193
	void *data;
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1194
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1195
	if (db->db_dirtycnt == 0)
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1196
		return (db->db.db_data);  /* Nothing is changing */
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1197
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1198
	for (drp = &db->db_last_dirty; (dr = *drp) != NULL; drp = &dr->dr_next)
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1199
		if (dr->dr_txg == tx->tx_txg)
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1200
			break;
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1201
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1202
	if (dr == NULL)
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1203
		data = NULL;
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1204
	else if (dr->dr_dbuf->db_dnode->dn_bonuslen == 0 &&
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1205
	    dr->dr_dbuf->db_blkid == DMU_SPILL_BLKID)
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1206
		data = dr->dt.dl.dr_data->b_data;
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1207
	else
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1208
		data = dr->dt.dl.dr_data;
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1209
	return (data);
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1210
}
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1211
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1212
void
12178
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1213
dmu_objset_userquota_get_ids(dnode_t *dn, boolean_t before, dmu_tx_t *tx)
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1214
{
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1215
	objset_t *os = dn->dn_objset;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1216
	void *data = NULL;
12178
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1217
	dmu_buf_impl_t *db = NULL;
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1218
	uint64_t *user, *group;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1219
	int flags = dn->dn_id_flags;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1220
	int error;
12178
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1221
	boolean_t have_spill = B_FALSE;
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1222
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1223
	if (!dmu_objset_userused_enabled(dn->dn_objset))
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1224
		return;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1225
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1226
	if (before && (flags & (DN_ID_CHKED_BONUS|DN_ID_OLD_EXIST|
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1227
	    DN_ID_CHKED_SPILL)))
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1228
		return;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1229
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1230
	if (before && dn->dn_bonuslen != 0)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1231
		data = DN_BONUS(dn->dn_phys);
12178
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1232
	else if (!before && dn->dn_bonuslen != 0) {
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1233
		if (dn->dn_bonus) {
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1234
			db = dn->dn_bonus;
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1235
			mutex_enter(&db->db_mtx);
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1236
			data = dmu_objset_userquota_find_data(db, tx);
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1237
		} else {
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1238
			data = DN_BONUS(dn->dn_phys);
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1239
		}
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1240
	} else if (dn->dn_bonuslen == 0 && dn->dn_bonustype == DMU_OT_SA) {
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1241
			int rf = 0;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1242
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1243
			if (RW_WRITE_HELD(&dn->dn_struct_rwlock))
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1244
				rf |= DB_RF_HAVESTRUCT;
12178
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1245
			error = dmu_spill_hold_by_dnode(dn, rf,
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1246
			    FTAG, (dmu_buf_t **)&db);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1247
			ASSERT(error == 0);
12178
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1248
			mutex_enter(&db->db_mtx);
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1249
			data = (before) ? db->db.db_data :
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1250
			    dmu_objset_userquota_find_data(db, tx);
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1251
			have_spill = B_TRUE;
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1252
	} else {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1253
		mutex_enter(&dn->dn_mtx);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1254
		dn->dn_id_flags |= DN_ID_CHKED_BONUS;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1255
		mutex_exit(&dn->dn_mtx);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1256
		return;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1257
	}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1258
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1259
	if (before) {
12178
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1260
		ASSERT(data);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1261
		user = &dn->dn_olduid;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1262
		group = &dn->dn_oldgid;
12178
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1263
	} else if (data) {
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1264
		user = &dn->dn_newuid;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1265
		group = &dn->dn_newgid;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1266
	}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1267
12178
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1268
	/*
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1269
	 * Must always call the callback in case the object
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1270
	 * type has changed and that type isn't an object type to track
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1271
	 */
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1272
	error = used_cbs[os->os_phys->os_type](dn->dn_bonustype, data,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1273
	    user, group);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1274
12178
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1275
	/*
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1276
	 * Preserve existing uid/gid when the callback can't determine
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1277
	 * what the new uid/gid are and the callback returned EEXIST.
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1278
	 * The EEXIST error tells us to just use the existing uid/gid.
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1279
	 * If we don't know what the old values are then just assign
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1280
	 * them to 0, since that is a new file  being created.
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1281
	 */
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1282
	if (!before && data == NULL && error == EEXIST) {
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1283
		if (flags & DN_ID_OLD_EXIST) {
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1284
			dn->dn_newuid = dn->dn_olduid;
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1285
			dn->dn_newgid = dn->dn_oldgid;
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1286
		} else {
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1287
			dn->dn_newuid = 0;
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1288
			dn->dn_newgid = 0;
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1289
		}
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1290
		error = 0;
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1291
	}
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1292
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1293
	if (db)
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1294
		mutex_exit(&db->db_mtx);
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1295
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1296
	mutex_enter(&dn->dn_mtx);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1297
	if (error == 0 && before)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1298
		dn->dn_id_flags |= DN_ID_OLD_EXIST;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1299
	if (error == 0 && !before)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1300
		dn->dn_id_flags |= DN_ID_NEW_EXIST;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1301
12178
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1302
	if (have_spill) {
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1303
		dn->dn_id_flags |= DN_ID_CHKED_SPILL;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1304
	} else {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1305
		dn->dn_id_flags |= DN_ID_CHKED_BONUS;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1306
	}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1307
	mutex_exit(&dn->dn_mtx);
12178
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1308
	if (have_spill)
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1309
		dmu_buf_rele((dmu_buf_t *)db, FTAG);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1310
}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11620
diff changeset
  1311
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1312
boolean_t
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1313
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
  1314
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1315
	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
  1316
	    OBJSET_FLAG_USERACCOUNTING_COMPLETE);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1317
}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1318
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1319
int
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1320
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
  1321
{
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1322
	uint64_t obj;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1323
	int err = 0;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1324
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1325
	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
  1326
		return (0);
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1327
	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
  1328
		return (ENOTSUP);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1329
	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
  1330
		return (EINVAL);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1331
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1332
	/*
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1333
	 * 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
  1334
	 * 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
  1335
	 * 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
  1336
	 * 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
  1337
	 * independently.
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1338
	 */
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1339
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1340
	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
  1341
		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
  1342
		dmu_buf_t *db;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1343
		int objerr;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1344
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1345
		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
  1346
			return (EINTR);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1347
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1348
		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
  1349
		if (objerr)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1350
			continue;
9951
a4895b3dd543 6842815 SUNWzfsu package dependency on SUNWPython is not captured
Lin Ling <Lin.Ling@Sun.COM>
parents: 9554
diff changeset
  1351
		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
  1352
		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
  1353
		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
  1354
		if (objerr) {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1355
			dmu_tx_abort(tx);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1356
			continue;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1357
		}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1358
		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
  1359
		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
  1360
		dmu_tx_commit(tx);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1361
	}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1362
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1363
	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
  1364
	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
  1365
	return (0);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1366
}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1367
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1368
void
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1369
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
  1370
    uint64_t *usedobjsp, uint64_t *availobjsp)
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1371
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1372
	dsl_dataset_space(os->os_dsl_dataset, refdbytesp, availbytesp,
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1373
	    usedobjsp, availobjsp);
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1374
}
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1375
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1376
uint64_t
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1377
dmu_objset_fsid_guid(objset_t *os)
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1378
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1379
	return (dsl_dataset_fsid_guid(os->os_dsl_dataset));
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1380
}
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1381
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1382
void
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1383
dmu_objset_fast_stat(objset_t *os, dmu_objset_stats_t *stat)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1384
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1385
	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
  1386
	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
  1387
		dsl_dataset_fast_stat(os->os_dsl_dataset, stat);
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1388
}
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1389
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1390
void
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1391
dmu_objset_stats(objset_t *os, nvlist_t *nv)
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1392
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1393
	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
  1394
	    os->os_phys->os_type == DMU_OST_META);
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1395
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1396
	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
  1397
		dsl_dataset_stats(os->os_dsl_dataset, nv);
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1398
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1399
	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
  1400
	    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
  1401
	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
  1402
	    dmu_objset_userspace_present(os));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1403
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1404
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1405
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1406
dmu_objset_is_snapshot(objset_t *os)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1407
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1408
	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
  1409
		return (dsl_dataset_is_snapshot(os->os_dsl_dataset));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1410
	else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1411
		return (B_FALSE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1412
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1413
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1414
int
6492
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6174
diff changeset
  1415
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
  1416
    boolean_t *conflict)
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6174
diff changeset
  1417
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1418
	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
  1419
	uint64_t ignored;
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6174
diff changeset
  1420
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6174
diff changeset
  1421
	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
  1422
		return (ENOENT);
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6174
diff changeset
  1423
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6174
diff changeset
  1424
	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
  1425
	    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
  1426
	    real, maxlen, conflict));
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6174
diff changeset
  1427
}
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6174
diff changeset
  1428
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6174
diff changeset
  1429
int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1430
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
  1431
    uint64_t *idp, uint64_t *offp, boolean_t *case_conflict)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1432
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1433
	dsl_dataset_t *ds = os->os_dsl_dataset;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1434
	zap_cursor_t cursor;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1435
	zap_attribute_t attr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1436
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1437
	if (ds->ds_phys->ds_snapnames_zapobj == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1438
		return (ENOENT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1439
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1440
	zap_cursor_init_serialized(&cursor,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1441
	    ds->ds_dir->dd_pool->dp_meta_objset,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1442
	    ds->ds_phys->ds_snapnames_zapobj, *offp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1443
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1444
	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
  1445
		zap_cursor_fini(&cursor);
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1446
		return (ENOENT);
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1447
	}
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1448
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1449
	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
  1450
		zap_cursor_fini(&cursor);
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1451
		return (ENAMETOOLONG);
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1452
	}
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1453
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1454
	(void) strcpy(name, attr.za_name);
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1455
	if (idp)
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1456
		*idp = attr.za_first_integer;
5663
029cc4273b57 6627223 gfs needs to support extended dirent flags
ck153898
parents: 5446
diff changeset
  1457
	if (case_conflict)
029cc4273b57 6627223 gfs needs to support extended dirent flags
ck153898
parents: 5446
diff changeset
  1458
		*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
  1459
	zap_cursor_advance(&cursor);
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1460
	*offp = zap_cursor_serialize(&cursor);
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1461
	zap_cursor_fini(&cursor);
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1462
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1463
	return (0);
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1464
}
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1465
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1466
int
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1467
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
  1468
    uint64_t *idp, uint64_t *offp)
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1469
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1470
	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
  1471
	zap_cursor_t cursor;
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1472
	zap_attribute_t attr;
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1473
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1474
	/* 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
  1475
	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
  1476
	    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
  1477
		return (ENOENT);
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1478
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1479
	zap_cursor_init_serialized(&cursor,
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1480
	    dd->dd_pool->dp_meta_objset,
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1481
	    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
  1482
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1483
	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
  1484
		zap_cursor_fini(&cursor);
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1485
		return (ENOENT);
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1486
	}
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1487
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1488
	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
  1489
		zap_cursor_fini(&cursor);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1490
		return (ENAMETOOLONG);
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1491
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1492
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1493
	(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
  1494
	if (idp)
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1495
		*idp = attr.za_first_integer;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1496
	zap_cursor_advance(&cursor);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1497
	*offp = zap_cursor_serialize(&cursor);
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1498
	zap_cursor_fini(&cursor);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1499
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1500
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1501
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1502
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1503
struct findarg {
11209
462283cb4096 6905188 panic: kernel heap corruption when doing "zfs rename -r"
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11165
diff changeset
  1504
	int (*func)(const char *, void *);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1505
	void *arg;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1506
};
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1507
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1508
/* ARGSUSED */
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1509
static int
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1510
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
  1511
{
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1512
	struct findarg *fa = arg;
11209
462283cb4096 6905188 panic: kernel heap corruption when doing "zfs rename -r"
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11165
diff changeset
  1513
	return (fa->func(dsname, fa->arg));
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1514
}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1515
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1516
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1517
 * 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
  1518
 * Perhaps change all callers to use dmu_objset_find_spa()?
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1519
 */
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1520
int
11209
462283cb4096 6905188 panic: kernel heap corruption when doing "zfs rename -r"
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11165
diff changeset
  1521
dmu_objset_find(char *name, int func(const char *, void *), void *arg,
462283cb4096 6905188 panic: kernel heap corruption when doing "zfs rename -r"
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11165
diff changeset
  1522
    int flags)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1523
{
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1524
	struct findarg fa;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1525
	fa.func = func;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1526
	fa.arg = arg;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1527
	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
  1528
}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1529
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1530
/*
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1531
 * 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
  1532
 */
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1533
int
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1534
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
  1535
    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
  1536
{
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1537
	dsl_dir_t *dd;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1538
	dsl_pool_t *dp;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1539
	dsl_dataset_t *ds;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1540
	zap_cursor_t zc;
3978
2dd668007b7a 6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents: 3897
diff changeset
  1541
	zap_attribute_t *attr;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1542
	char *child;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1543
	uint64_t thisobj;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1544
	int err;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1545
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1546
	if (name == NULL)
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1547
		name = spa_name(spa);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1548
	err = dsl_dir_open_spa(spa, name, FTAG, &dd, NULL);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
  1549
	if (err)
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1550
		return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1551
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1552
	/* 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
  1553
	if (dd->dd_myname[0] == '$') {
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1554
		dsl_dir_close(dd, FTAG);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1555
		return (0);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1556
	}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1557
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1558
	thisobj = dd->dd_phys->dd_head_dataset_obj;
3978
2dd668007b7a 6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents: 3897
diff changeset
  1559
	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
  1560
	dp = dd->dd_pool;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1561
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1562
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1563
	 * Iterate over all children.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1564
	 */
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2391
diff changeset
  1565
	if (flags & DS_FIND_CHILDREN) {
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1566
		for (zap_cursor_init(&zc, dp->dp_meta_objset,
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2391
diff changeset
  1567
		    dd->dd_phys->dd_child_dir_zapobj);
3978
2dd668007b7a 6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents: 3897
diff changeset
  1568
		    zap_cursor_retrieve(&zc, attr) == 0;
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2391
diff changeset
  1569
		    (void) zap_cursor_advance(&zc)) {
3978
2dd668007b7a 6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents: 3897
diff changeset
  1570
			ASSERT(attr->za_integer_length == sizeof (uint64_t));
2dd668007b7a 6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents: 3897
diff changeset
  1571
			ASSERT(attr->za_num_integers == 1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1572
11165
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11022
diff changeset
  1573
			child = kmem_asprintf("%s/%s", name, attr->za_name);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1574
			err = dmu_objset_find_spa(spa, child, func, arg, flags);
11165
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11022
diff changeset
  1575
			strfree(child);
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2391
diff changeset
  1576
			if (err)
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2391
diff changeset
  1577
				break;
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2391
diff changeset
  1578
		}
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2391
diff changeset
  1579
		zap_cursor_fini(&zc);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1580
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2391
diff changeset
  1581
		if (err) {
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2391
diff changeset
  1582
			dsl_dir_close(dd, FTAG);
3978
2dd668007b7a 6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents: 3897
diff changeset
  1583
			kmem_free(attr, sizeof (zap_attribute_t));
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2391
diff changeset
  1584
			return (err);
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2391
diff changeset
  1585
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1586
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1587
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1588
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1589
	 * Iterate over all snapshots.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1590
	 */
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1591
	if (flags & DS_FIND_SNAPSHOTS) {
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1592
		if (!dsl_pool_sync_context(dp))
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1593
			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
  1594
		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
  1595
		if (!dsl_pool_sync_context(dp))
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1596
			rw_exit(&dp->dp_config_rwlock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1597
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1598
		if (err == 0) {
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1599
			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
  1600
			dsl_dataset_rele(ds, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1601
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1602
			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
  1603
			    zap_cursor_retrieve(&zc, attr) == 0;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1604
			    (void) zap_cursor_advance(&zc)) {
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1605
				ASSERT(attr->za_integer_length ==
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1606
				    sizeof (uint64_t));
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1607
				ASSERT(attr->za_num_integers == 1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1608
11165
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11022
diff changeset
  1609
				child = kmem_asprintf("%s@%s",
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11022
diff changeset
  1610
				    name, attr->za_name);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1611
				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
  1612
				    child, arg);
11165
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11022
diff changeset
  1613
				strfree(child);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1614
				if (err)
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1615
					break;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1616
			}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1617
			zap_cursor_fini(&zc);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1618
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1619
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1620
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1621
	dsl_dir_close(dd, FTAG);
3978
2dd668007b7a 6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents: 3897
diff changeset
  1622
	kmem_free(attr, sizeof (zap_attribute_t));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1623
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1624
	if (err)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1625
		return (err);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1626
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1627
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1628
	 * Apply to self if appropriate.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1629
	 */
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1630
	err = func(spa, thisobj, name, arg);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1631
	return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1632
}
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  1633
8415
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1634
/* ARGSUSED */
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1635
int
11209
462283cb4096 6905188 panic: kernel heap corruption when doing "zfs rename -r"
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11165
diff changeset
  1636
dmu_objset_prefetch(const char *name, void *arg)
8415
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1637
{
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1638
	dsl_dataset_t *ds;
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1639
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1640
	if (dsl_dataset_hold(name, FTAG, &ds))
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1641
		return (0);
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1642
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1643
	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
  1644
		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
  1645
		if (ds->ds_objset == NULL) {
8415
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1646
			uint32_t aflags = ARC_NOWAIT | ARC_PREFETCH;
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1647
			zbookmark_t zb;
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1648
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
  1649
			SET_BOOKMARK(&zb, ds->ds_object, ZB_ROOT_OBJECT,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10801
diff changeset
  1650
			    ZB_ROOT_LEVEL, ZB_ROOT_BLKID);
8415
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1651
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12294
diff changeset
  1652
			(void) dsl_read_nolock(NULL, dsl_dataset_get_spa(ds),
8415
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1653
			    &ds->ds_phys->ds_bp, NULL, NULL,
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1654
			    ZIO_PRIORITY_ASYNC_READ,
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1655
			    ZIO_FLAG_CANFAIL | ZIO_FLAG_SPECULATIVE,
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1656
			    &aflags, &zb);
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1657
		}
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1658
		mutex_exit(&ds->ds_opening_lock);
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1659
	}
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1660
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1661
	dsl_dataset_rele(ds, FTAG);
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1662
	return (0);
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1663
}
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1664
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  1665
void
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  1666
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
  1667
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1668
	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
  1669
	os->os_user_ptr = user_ptr;
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  1670
}
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  1671
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  1672
void *
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  1673
dmu_objset_get_user(objset_t *os)
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  1674
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1675
	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
  1676
	return (os->os_user_ptr);
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  1677
}