usr/src/uts/common/fs/zfs/dmu_object.c
author Matthew Ahrens <mahrens@delphix.com>
Fri, 08 Mar 2013 10:41:28 -0800
changeset 13980 d7059eb1884c
parent 12684 397e44ebb8a9
permissions -rw-r--r--
3598 want to dtrace when errors are generated in zfs Reviewed by: Dan Kimmel <[email protected]> Reviewed by: Adam Leventhal <[email protected]> Reviewed by: Christopher Siden <[email protected]> Approved by: Garrett D'Amore <[email protected]>
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: 789
diff changeset
     5
 * Common Development and Distribution License (the "License").
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
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: 10298
diff changeset
    22
 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
13980
d7059eb1884c 3598 want to dtrace when errors are generated in zfs
Matthew Ahrens <mahrens@delphix.com>
parents: 12684
diff changeset
    23
 * Copyright (c) 2013 by Delphix. All rights reserved.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    24
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    25
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    26
#include <sys/dmu.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    27
#include <sys/dmu_objset.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    28
#include <sys/dmu_tx.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    29
#include <sys/dnode.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    30
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    31
uint64_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    32
dmu_object_alloc(objset_t *os, dmu_object_type_t ot, int blocksize,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    33
    dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    34
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    35
	uint64_t object;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    36
	uint64_t L2_dnode_count = DNODES_PER_BLOCK <<
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12178
diff changeset
    37
	    (DMU_META_DNODE(os)->dn_indblkshift - SPA_BLKPTRSHIFT);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
    38
	dnode_t *dn = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    39
	int restarted = B_FALSE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    40
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9299
diff changeset
    41
	mutex_enter(&os->os_obj_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    42
	for (;;) {
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9299
diff changeset
    43
		object = os->os_obj_next;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    44
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    45
		 * Each time we polish off an L2 bp worth of dnodes
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    46
		 * (2^13 objects), move to another L2 bp that's still
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    47
		 * reasonably sparse (at most 1/4 full).  Look from the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    48
		 * beginning once, but after that keep looking from here.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    49
		 * If we can't find one, just keep going from here.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    50
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    51
		if (P2PHASE(object, L2_dnode_count) == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    52
			uint64_t offset = restarted ? object << DNODE_SHIFT : 0;
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12178
diff changeset
    53
			int error = dnode_next_offset(DMU_META_DNODE(os),
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 3025
diff changeset
    54
			    DNODE_FIND_HOLE,
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 3025
diff changeset
    55
			    &offset, 2, DNODES_PER_BLOCK >> 2, 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    56
			restarted = B_TRUE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    57
			if (error == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    58
				object = offset >> DNODE_SHIFT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    59
		}
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9299
diff changeset
    60
		os->os_obj_next = ++object;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    61
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
    62
		/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
    63
		 * XXX We should check for an i/o error here and return
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
    64
		 * up to our caller.  Actually we should pre-read it in
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
    65
		 * dmu_tx_assign(), but there is currently no mechanism
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
    66
		 * to do so.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
    67
		 */
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9299
diff changeset
    68
		(void) dnode_hold_impl(os, object, DNODE_MUST_BE_FREE,
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
    69
		    FTAG, &dn);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    70
		if (dn)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    71
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    72
3025
4e5ee8301d84 6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents: 1544
diff changeset
    73
		if (dmu_object_next(os, &object, B_TRUE, 0) == 0)
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9299
diff changeset
    74
			os->os_obj_next = object - 1;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    75
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    76
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    77
	dnode_allocate(dn, ot, blocksize, 0, bonustype, bonuslen, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    78
	dnode_rele(dn, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    79
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9299
diff changeset
    80
	mutex_exit(&os->os_obj_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    81
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    82
	dmu_tx_add_new_object(tx, os, object);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    83
	return (object);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    84
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    85
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    86
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    87
dmu_object_claim(objset_t *os, uint64_t object, dmu_object_type_t ot,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    88
    int blocksize, dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    89
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    90
	dnode_t *dn;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
    91
	int err;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    92
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
    93
	if (object == DMU_META_DNODE_OBJECT && !dmu_tx_private_ok(tx))
13980
d7059eb1884c 3598 want to dtrace when errors are generated in zfs
Matthew Ahrens <mahrens@delphix.com>
parents: 12684
diff changeset
    94
		return (SET_ERROR(EBADF));
789
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: 9299
diff changeset
    96
	err = dnode_hold_impl(os, object, DNODE_MUST_BE_FREE, FTAG, &dn);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
    97
	if (err)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
    98
		return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    99
	dnode_allocate(dn, ot, blocksize, 0, bonustype, bonuslen, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   100
	dnode_rele(dn, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   101
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   102
	dmu_tx_add_new_object(tx, os, object);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   103
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   104
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   105
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   106
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   107
dmu_object_reclaim(objset_t *os, uint64_t object, dmu_object_type_t ot,
8986
45c289aff7c9 6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 6992
diff changeset
   108
    int blocksize, dmu_object_type_t bonustype, int bonuslen)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   109
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   110
	dnode_t *dn;
8986
45c289aff7c9 6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 6992
diff changeset
   111
	dmu_tx_t *tx;
45c289aff7c9 6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 6992
diff changeset
   112
	int nblkptr;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   113
	int err;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   114
8986
45c289aff7c9 6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 6992
diff changeset
   115
	if (object == DMU_META_DNODE_OBJECT)
13980
d7059eb1884c 3598 want to dtrace when errors are generated in zfs
Matthew Ahrens <mahrens@delphix.com>
parents: 12684
diff changeset
   116
		return (SET_ERROR(EBADF));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   117
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9299
diff changeset
   118
	err = dnode_hold_impl(os, object, DNODE_MUST_BE_ALLOCATED,
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   119
	    FTAG, &dn);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   120
	if (err)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   121
		return (err);
8986
45c289aff7c9 6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 6992
diff changeset
   122
45c289aff7c9 6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 6992
diff changeset
   123
	if (dn->dn_type == ot && dn->dn_datablksz == blocksize &&
45c289aff7c9 6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 6992
diff changeset
   124
	    dn->dn_bonustype == bonustype && dn->dn_bonuslen == bonuslen) {
45c289aff7c9 6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 6992
diff changeset
   125
		/* nothing is changing, this is a noop */
45c289aff7c9 6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 6992
diff changeset
   126
		dnode_rele(dn, FTAG);
45c289aff7c9 6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 6992
diff changeset
   127
		return (0);
45c289aff7c9 6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 6992
diff changeset
   128
	}
45c289aff7c9 6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 6992
diff changeset
   129
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: 10298
diff changeset
   130
	if (bonustype == DMU_OT_SA) {
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: 10298
diff changeset
   131
		nblkptr = 1;
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: 10298
diff changeset
   132
	} 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: 10298
diff changeset
   133
		nblkptr = 1 + ((DN_MAX_BONUSLEN - bonuslen) >> SPA_BLKPTRSHIFT);
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: 10298
diff changeset
   134
	}
8986
45c289aff7c9 6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 6992
diff changeset
   135
45c289aff7c9 6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 6992
diff changeset
   136
	/*
45c289aff7c9 6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 6992
diff changeset
   137
	 * If we are losing blkptrs or changing the block size this must
45c289aff7c9 6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 6992
diff changeset
   138
	 * be a new file instance.   We must clear out the previous file
45c289aff7c9 6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 6992
diff changeset
   139
	 * contents before we can change this type of metadata in the dnode.
45c289aff7c9 6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 6992
diff changeset
   140
	 */
9299
8809e849f63e 6783818 Incremental stream receive panics system
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8986
diff changeset
   141
	if (dn->dn_nblkptr > nblkptr || dn->dn_datablksz != blocksize) {
8809e849f63e 6783818 Incremental stream receive panics system
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8986
diff changeset
   142
		err = dmu_free_long_range(os, object, 0, DMU_OBJECT_END);
8809e849f63e 6783818 Incremental stream receive panics system
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8986
diff changeset
   143
		if (err)
8809e849f63e 6783818 Incremental stream receive panics system
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8986
diff changeset
   144
			goto out;
8809e849f63e 6783818 Incremental stream receive panics system
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8986
diff changeset
   145
	}
8809e849f63e 6783818 Incremental stream receive panics system
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8986
diff changeset
   146
8809e849f63e 6783818 Incremental stream receive panics system
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8986
diff changeset
   147
	tx = dmu_tx_create(os);
8809e849f63e 6783818 Incremental stream receive panics system
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8986
diff changeset
   148
	dmu_tx_hold_bonus(tx, object);
8809e849f63e 6783818 Incremental stream receive panics system
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8986
diff changeset
   149
	err = dmu_tx_assign(tx, TXG_WAIT);
8809e849f63e 6783818 Incremental stream receive panics system
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8986
diff changeset
   150
	if (err) {
8809e849f63e 6783818 Incremental stream receive panics system
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8986
diff changeset
   151
		dmu_tx_abort(tx);
8809e849f63e 6783818 Incremental stream receive panics system
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8986
diff changeset
   152
		goto out;
8809e849f63e 6783818 Incremental stream receive panics system
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8986
diff changeset
   153
	}
8986
45c289aff7c9 6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 6992
diff changeset
   154
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   155
	dnode_reallocate(dn, ot, blocksize, bonustype, bonuslen, tx);
8986
45c289aff7c9 6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 6992
diff changeset
   156
45c289aff7c9 6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 6992
diff changeset
   157
	dmu_tx_commit(tx);
9299
8809e849f63e 6783818 Incremental stream receive panics system
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8986
diff changeset
   158
out:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   159
	dnode_rele(dn, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   160
9299
8809e849f63e 6783818 Incremental stream receive panics system
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8986
diff changeset
   161
	return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   162
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   163
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   164
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   165
dmu_object_free(objset_t *os, uint64_t object, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   166
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   167
	dnode_t *dn;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   168
	int err;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   169
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   170
	ASSERT(object != DMU_META_DNODE_OBJECT || dmu_tx_private_ok(tx));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   171
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9299
diff changeset
   172
	err = dnode_hold_impl(os, object, DNODE_MUST_BE_ALLOCATED,
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   173
	    FTAG, &dn);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   174
	if (err)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   175
		return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   176
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   177
	ASSERT(dn->dn_type != DMU_OT_NONE);
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 3025
diff changeset
   178
	dnode_free_range(dn, 0, DMU_OBJECT_END, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   179
	dnode_free(dn, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   180
	dnode_rele(dn, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   181
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   182
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   183
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   184
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   185
int
3025
4e5ee8301d84 6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents: 1544
diff changeset
   186
dmu_object_next(objset_t *os, uint64_t *objectp, boolean_t hole, uint64_t txg)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   187
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   188
	uint64_t offset = (*objectp + 1) << DNODE_SHIFT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   189
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   190
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12178
diff changeset
   191
	error = dnode_next_offset(DMU_META_DNODE(os),
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 3025
diff changeset
   192
	    (hole ? DNODE_FIND_HOLE : 0), &offset, 0, DNODES_PER_BLOCK, txg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   193
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   194
	*objectp = offset >> DNODE_SHIFT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   195
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   196
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   197
}