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