usr/src/uts/common/fs/zfs/zap_micro.c
author Christopher Siden <chris.siden@delphix.com>
Mon, 21 May 2012 12:11:39 -0700
changeset 13700 2889e2596bd6
parent 13524 f0e12b33f77c
child 13764 38b4aca480b3
permissions -rw-r--r--
2619 asynchronous destruction of ZFS file systems 2747 SPA versioning with zfs feature flags Reviewed by: Matt Ahrens <[email protected]> Reviewed by: George Wilson <[email protected]> Reviewed by: Richard Lowe <[email protected]> Reviewed by: Dan Kruchinin <[email protected]> Approved by: Eric Schrock <[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
1491
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
     5
 * Common Development and Distribution License (the "License").
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
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
/*
12285
d736d62dcca2 6944833 Avoid prefetching dbufs in dmu_sync() path
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11165
diff changeset
    22
 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13524
diff changeset
    23
 * Copyright (c) 2012 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
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
    26
#include <sys/zio.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    27
#include <sys/spa.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    28
#include <sys/dmu.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    29
#include <sys/zfs_context.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    30
#include <sys/zap.h>
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
    31
#include <sys/refcount.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    32
#include <sys/zap_impl.h>
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
    33
#include <sys/zap_leaf.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    34
#include <sys/avl.h>
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
    35
#include <sys/arc.h>
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5497
diff changeset
    36
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5497
diff changeset
    37
#ifdef _KERNEL
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5497
diff changeset
    38
#include <sys/sunddi.h>
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5497
diff changeset
    39
#endif
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    40
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
    41
static int mzap_upgrade(zap_t **zapp, dmu_tx_t *tx, zap_flags_t flags);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
    42
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
    43
uint64_t
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
    44
zap_getflags(zap_t *zap)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
    45
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
    46
	if (zap->zap_ismicro)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
    47
		return (0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
    48
	return (zap->zap_u.zap_fat.zap_phys->zap_flags);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
    49
}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    50
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
    51
int
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
    52
zap_hashbits(zap_t *zap)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
    53
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
    54
	if (zap_getflags(zap) & ZAP_FLAG_HASH64)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
    55
		return (48);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
    56
	else
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
    57
		return (28);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
    58
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
    59
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
    60
uint32_t
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
    61
zap_maxcd(zap_t *zap)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
    62
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
    63
	if (zap_getflags(zap) & ZAP_FLAG_HASH64)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
    64
		return ((1<<16)-1);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
    65
	else
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
    66
		return (-1U);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
    67
}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    68
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
    69
static uint64_t
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
    70
zap_hash(zap_name_t *zn)
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
    71
{
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
    72
	zap_t *zap = zn->zn_zap;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
    73
	uint64_t h = 0;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
    74
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
    75
	if (zap_getflags(zap) & ZAP_FLAG_PRE_HASHED_KEY) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
    76
		ASSERT(zap_getflags(zap) & ZAP_FLAG_UINT64_KEY);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
    77
		h = *(uint64_t *)zn->zn_key_orig;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
    78
	} else {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
    79
		h = zap->zap_salt;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
    80
		ASSERT(h != 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
    81
		ASSERT(zfs_crc64_table[128] == ZFS_CRC64_POLY);
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
    82
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11022
diff changeset
    83
		if (zap_getflags(zap) & ZAP_FLAG_UINT64_KEY) {
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11022
diff changeset
    84
			int i;
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11022
diff changeset
    85
			const uint64_t *wp = zn->zn_key_norm;
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11022
diff changeset
    86
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11022
diff changeset
    87
			ASSERT(zn->zn_key_intlen == 8);
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11022
diff changeset
    88
			for (i = 0; i < zn->zn_key_norm_numints; wp++, i++) {
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11022
diff changeset
    89
				int j;
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11022
diff changeset
    90
				uint64_t word = *wp;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
    91
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
    92
				for (j = 0; j < zn->zn_key_intlen; j++) {
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11022
diff changeset
    93
					h = (h >> 8) ^
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11022
diff changeset
    94
					    zfs_crc64_table[(h ^ word) & 0xFF];
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11022
diff changeset
    95
					word >>= NBBY;
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11022
diff changeset
    96
				}
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11022
diff changeset
    97
			}
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11022
diff changeset
    98
		} else {
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11022
diff changeset
    99
			int i, len;
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11022
diff changeset
   100
			const uint8_t *cp = zn->zn_key_norm;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   101
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
   102
			/*
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11022
diff changeset
   103
			 * We previously stored the terminating null on
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11022
diff changeset
   104
			 * disk, but didn't hash it, so we need to
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11022
diff changeset
   105
			 * continue to not hash it.  (The
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11022
diff changeset
   106
			 * zn_key_*_numints includes the terminating
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11022
diff changeset
   107
			 * null for non-binary keys.)
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11022
diff changeset
   108
			 */
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11022
diff changeset
   109
			len = zn->zn_key_norm_numints - 1;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   110
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
   111
			ASSERT(zn->zn_key_intlen == 1);
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11022
diff changeset
   112
			for (i = 0; i < len; cp++, i++) {
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11022
diff changeset
   113
				h = (h >> 8) ^
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11022
diff changeset
   114
				    zfs_crc64_table[(h ^ *cp) & 0xFF];
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11022
diff changeset
   115
			}
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11022
diff changeset
   116
		}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   117
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   118
	/*
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   119
	 * Don't use all 64 bits, since we need some in the cookie for
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   120
	 * the collision differentiator.  We MUST use the high bits,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   121
	 * since those are the ones that we first pay attention to when
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   122
	 * chosing the bucket.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   123
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   124
	h &= ~((1ULL << (64 - zap_hashbits(zap))) - 1);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   125
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   126
	return (h);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   127
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   128
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   129
static int
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   130
zap_normalize(zap_t *zap, const char *name, char *namenorm)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   131
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   132
	size_t inlen, outlen;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   133
	int err;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   134
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   135
	ASSERT(!(zap_getflags(zap) & ZAP_FLAG_UINT64_KEY));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   136
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   137
	inlen = strlen(name) + 1;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   138
	outlen = ZAP_MAXNAMELEN;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   139
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   140
	err = 0;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   141
	(void) u8_textprep_str((char *)name, &inlen, namenorm, &outlen,
8748
a2af983fad1a 6783995 file creation sometimes failing within a zfs where casesensitivity=mixed
Tim Haley <Tim.Haley@Sun.COM>
parents: 6492
diff changeset
   142
	    zap->zap_normflags | U8_TEXTPREP_IGNORE_NULL |
a2af983fad1a 6783995 file creation sometimes failing within a zfs where casesensitivity=mixed
Tim Haley <Tim.Haley@Sun.COM>
parents: 6492
diff changeset
   143
	    U8_TEXTPREP_IGNORE_INVALID, U8_UNICODE_LATEST, &err);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   144
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   145
	return (err);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   146
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   147
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   148
boolean_t
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   149
zap_match(zap_name_t *zn, const char *matchname)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   150
{
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   151
	ASSERT(!(zap_getflags(zn->zn_zap) & ZAP_FLAG_UINT64_KEY));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   152
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   153
	if (zn->zn_matchtype == MT_FIRST) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   154
		char norm[ZAP_MAXNAMELEN];
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   155
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   156
		if (zap_normalize(zn->zn_zap, matchname, norm) != 0)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   157
			return (B_FALSE);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   158
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   159
		return (strcmp(zn->zn_key_norm, norm) == 0);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   160
	} else {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   161
		/* MT_BEST or MT_EXACT */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   162
		return (strcmp(zn->zn_key_orig, matchname) == 0);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   163
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   164
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   165
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   166
void
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   167
zap_name_free(zap_name_t *zn)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   168
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   169
	kmem_free(zn, sizeof (zap_name_t));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   170
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   171
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   172
zap_name_t *
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   173
zap_name_alloc(zap_t *zap, const char *key, matchtype_t mt)
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   174
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   175
	zap_name_t *zn = kmem_alloc(sizeof (zap_name_t), KM_SLEEP);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   176
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   177
	zn->zn_zap = zap;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   178
	zn->zn_key_intlen = sizeof (*key);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   179
	zn->zn_key_orig = key;
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
   180
	zn->zn_key_orig_numints = strlen(zn->zn_key_orig) + 1;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   181
	zn->zn_matchtype = mt;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   182
	if (zap->zap_normflags) {
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   183
		if (zap_normalize(zap, key, zn->zn_normbuf) != 0) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   184
			zap_name_free(zn);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   185
			return (NULL);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   186
		}
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   187
		zn->zn_key_norm = zn->zn_normbuf;
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
   188
		zn->zn_key_norm_numints = strlen(zn->zn_key_norm) + 1;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   189
	} else {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   190
		if (mt != MT_EXACT) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   191
			zap_name_free(zn);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   192
			return (NULL);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   193
		}
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   194
		zn->zn_key_norm = zn->zn_key_orig;
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
   195
		zn->zn_key_norm_numints = zn->zn_key_orig_numints;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   196
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   197
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   198
	zn->zn_hash = zap_hash(zn);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   199
	return (zn);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   200
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   201
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   202
zap_name_t *
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   203
zap_name_alloc_uint64(zap_t *zap, const uint64_t *key, int numints)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   204
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   205
	zap_name_t *zn = kmem_alloc(sizeof (zap_name_t), KM_SLEEP);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   206
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   207
	ASSERT(zap->zap_normflags == 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   208
	zn->zn_zap = zap;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   209
	zn->zn_key_intlen = sizeof (*key);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   210
	zn->zn_key_orig = zn->zn_key_norm = key;
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
   211
	zn->zn_key_orig_numints = zn->zn_key_norm_numints = numints;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   212
	zn->zn_matchtype = MT_EXACT;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   213
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   214
	zn->zn_hash = zap_hash(zn);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   215
	return (zn);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   216
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   217
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   218
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   219
mzap_byteswap(mzap_phys_t *buf, size_t size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   220
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   221
	int i, max;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   222
	buf->mz_block_type = BSWAP_64(buf->mz_block_type);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   223
	buf->mz_salt = BSWAP_64(buf->mz_salt);
6492
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 5498
diff changeset
   224
	buf->mz_normflags = BSWAP_64(buf->mz_normflags);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   225
	max = (size / MZAP_ENT_LEN) - 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   226
	for (i = 0; i < max; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   227
		buf->mz_chunk[i].mze_value =
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   228
		    BSWAP_64(buf->mz_chunk[i].mze_value);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   229
		buf->mz_chunk[i].mze_cd =
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   230
		    BSWAP_32(buf->mz_chunk[i].mze_cd);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   231
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   232
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   233
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   234
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   235
zap_byteswap(void *buf, size_t size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   236
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   237
	uint64_t block_type;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   238
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   239
	block_type = *(uint64_t *)buf;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   240
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2641
diff changeset
   241
	if (block_type == ZBT_MICRO || block_type == BSWAP_64(ZBT_MICRO)) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   242
		/* ASSERT(magic == ZAP_LEAF_MAGIC); */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   243
		mzap_byteswap(buf, size);
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2641
diff changeset
   244
	} else {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   245
		fzap_byteswap(buf, size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   246
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   247
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   248
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   249
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   250
mze_compare(const void *arg1, const void *arg2)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   251
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   252
	const mzap_ent_t *mze1 = arg1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   253
	const mzap_ent_t *mze2 = arg2;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   254
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   255
	if (mze1->mze_hash > mze2->mze_hash)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   256
		return (+1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   257
	if (mze1->mze_hash < mze2->mze_hash)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   258
		return (-1);
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
   259
	if (mze1->mze_cd > mze2->mze_cd)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   260
		return (+1);
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
   261
	if (mze1->mze_cd < mze2->mze_cd)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   262
		return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   263
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   264
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   265
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   266
static void
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
   267
mze_insert(zap_t *zap, int chunkid, uint64_t hash)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   268
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   269
	mzap_ent_t *mze;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   270
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   271
	ASSERT(zap->zap_ismicro);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   272
	ASSERT(RW_WRITE_HELD(&zap->zap_rwlock));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   273
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   274
	mze = kmem_alloc(sizeof (mzap_ent_t), KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   275
	mze->mze_chunkid = chunkid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   276
	mze->mze_hash = hash;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
   277
	mze->mze_cd = MZE_PHYS(zap, mze)->mze_cd;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
   278
	ASSERT(MZE_PHYS(zap, mze)->mze_name[0] != 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   279
	avl_add(&zap->zap_m.zap_avl, mze);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   280
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   281
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   282
static mzap_ent_t *
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   283
mze_find(zap_name_t *zn)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   284
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   285
	mzap_ent_t mze_tofind;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   286
	mzap_ent_t *mze;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   287
	avl_index_t idx;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   288
	avl_tree_t *avl = &zn->zn_zap->zap_m.zap_avl;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   289
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   290
	ASSERT(zn->zn_zap->zap_ismicro);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   291
	ASSERT(RW_LOCK_HELD(&zn->zn_zap->zap_rwlock));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   292
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   293
	mze_tofind.mze_hash = zn->zn_hash;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
   294
	mze_tofind.mze_cd = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   295
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   296
again:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   297
	mze = avl_find(avl, &mze_tofind, &idx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   298
	if (mze == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   299
		mze = avl_nearest(avl, idx, AVL_AFTER);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   300
	for (; mze && mze->mze_hash == zn->zn_hash; mze = AVL_NEXT(avl, mze)) {
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
   301
		ASSERT3U(mze->mze_cd, ==, MZE_PHYS(zn->zn_zap, mze)->mze_cd);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
   302
		if (zap_match(zn, MZE_PHYS(zn->zn_zap, mze)->mze_name))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   303
			return (mze);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   304
	}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   305
	if (zn->zn_matchtype == MT_BEST) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   306
		zn->zn_matchtype = MT_FIRST;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   307
		goto again;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   308
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   309
	return (NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   310
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   311
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   312
static uint32_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   313
mze_find_unused_cd(zap_t *zap, uint64_t hash)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   314
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   315
	mzap_ent_t mze_tofind;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   316
	mzap_ent_t *mze;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   317
	avl_index_t idx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   318
	avl_tree_t *avl = &zap->zap_m.zap_avl;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   319
	uint32_t cd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   320
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   321
	ASSERT(zap->zap_ismicro);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   322
	ASSERT(RW_LOCK_HELD(&zap->zap_rwlock));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   323
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   324
	mze_tofind.mze_hash = hash;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
   325
	mze_tofind.mze_cd = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   326
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   327
	cd = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   328
	for (mze = avl_find(avl, &mze_tofind, &idx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   329
	    mze && mze->mze_hash == hash; mze = AVL_NEXT(avl, mze)) {
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
   330
		if (mze->mze_cd != cd)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   331
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   332
		cd++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   333
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   334
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   335
	return (cd);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   336
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   337
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   338
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   339
mze_remove(zap_t *zap, mzap_ent_t *mze)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   340
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   341
	ASSERT(zap->zap_ismicro);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   342
	ASSERT(RW_WRITE_HELD(&zap->zap_rwlock));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   343
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   344
	avl_remove(&zap->zap_m.zap_avl, mze);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   345
	kmem_free(mze, sizeof (mzap_ent_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   346
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   347
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   348
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   349
mze_destroy(zap_t *zap)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   350
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   351
	mzap_ent_t *mze;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   352
	void *avlcookie = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   353
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   354
	while (mze = avl_destroy_nodes(&zap->zap_m.zap_avl, &avlcookie))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   355
		kmem_free(mze, sizeof (mzap_ent_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   356
	avl_destroy(&zap->zap_m.zap_avl);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   357
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   358
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   359
static zap_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   360
mzap_open(objset_t *os, uint64_t obj, dmu_buf_t *db)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   361
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   362
	zap_t *winner;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   363
	zap_t *zap;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   364
	int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   365
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   366
	ASSERT3U(MZAP_ENT_LEN, ==, sizeof (mzap_ent_phys_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   367
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   368
	zap = kmem_zalloc(sizeof (zap_t), KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   369
	rw_init(&zap->zap_rwlock, 0, 0, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   370
	rw_enter(&zap->zap_rwlock, RW_WRITER);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   371
	zap->zap_objset = os;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   372
	zap->zap_object = obj;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   373
	zap->zap_dbuf = db;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   374
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   375
	if (*(uint64_t *)db->db_data != ZBT_MICRO) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   376
		mutex_init(&zap->zap_f.zap_num_entries_mtx, 0, 0, 0);
1491
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   377
		zap->zap_f.zap_block_shift = highbit(db->db_size) - 1;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   378
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   379
		zap->zap_ismicro = TRUE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   380
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   381
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   382
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   383
	 * Make sure that zap_ismicro is set before we let others see
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   384
	 * it, because zap_lockdir() checks zap_ismicro without the lock
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   385
	 * held.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   386
	 */
2641
967ea438b194 6462174 zap_update() likes to return 0
ahrens
parents: 1544
diff changeset
   387
	winner = dmu_buf_set_user(db, zap, &zap->zap_m.zap_phys, zap_evict);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   388
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   389
	if (winner != NULL) {
4831
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 2856
diff changeset
   390
		rw_exit(&zap->zap_rwlock);
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 2856
diff changeset
   391
		rw_destroy(&zap->zap_rwlock);
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 2856
diff changeset
   392
		if (!zap->zap_ismicro)
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 2856
diff changeset
   393
			mutex_destroy(&zap->zap_f.zap_num_entries_mtx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   394
		kmem_free(zap, sizeof (zap_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   395
		return (winner);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   396
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   397
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   398
	if (zap->zap_ismicro) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   399
		zap->zap_salt = zap->zap_m.zap_phys->mz_salt;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   400
		zap->zap_normflags = zap->zap_m.zap_phys->mz_normflags;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   401
		zap->zap_m.zap_num_chunks = db->db_size / MZAP_ENT_LEN - 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   402
		avl_create(&zap->zap_m.zap_avl, mze_compare,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   403
		    sizeof (mzap_ent_t), offsetof(mzap_ent_t, mze_node));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   404
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   405
		for (i = 0; i < zap->zap_m.zap_num_chunks; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   406
			mzap_ent_phys_t *mze =
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   407
			    &zap->zap_m.zap_phys->mz_chunk[i];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   408
			if (mze->mze_name[0]) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   409
				zap_name_t *zn;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   410
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   411
				zap->zap_m.zap_num_entries++;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   412
				zn = zap_name_alloc(zap, mze->mze_name,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   413
				    MT_EXACT);
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
   414
				mze_insert(zap, i, zn->zn_hash);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   415
				zap_name_free(zn);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   416
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   417
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   418
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   419
		zap->zap_salt = zap->zap_f.zap_phys->zap_salt;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   420
		zap->zap_normflags = zap->zap_f.zap_phys->zap_normflags;
1491
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   421
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   422
		ASSERT3U(sizeof (struct zap_leaf_header), ==,
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   423
		    2*ZAP_LEAF_CHUNKSIZE);
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   424
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   425
		/*
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   426
		 * The embedded pointer table should not overlap the
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   427
		 * other members.
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   428
		 */
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   429
		ASSERT3P(&ZAP_EMBEDDED_PTRTBL_ENT(zap, 0), >,
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   430
		    &zap->zap_f.zap_phys->zap_salt);
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   431
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   432
		/*
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   433
		 * The embedded pointer table should end at the end of
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   434
		 * the block
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   435
		 */
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   436
		ASSERT3U((uintptr_t)&ZAP_EMBEDDED_PTRTBL_ENT(zap,
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   437
		    1<<ZAP_EMBEDDED_PTRTBL_SHIFT(zap)) -
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   438
		    (uintptr_t)zap->zap_f.zap_phys, ==,
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   439
		    zap->zap_dbuf->db_size);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   440
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   441
	rw_exit(&zap->zap_rwlock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   442
	return (zap);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   443
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   444
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   445
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   446
zap_lockdir(objset_t *os, uint64_t obj, dmu_tx_t *tx,
5384
8eba72d775e9 6623831 assertion failed in dmu_tx_willuse_space() from mzap_upgrade()
ahrens
parents: 5331
diff changeset
   447
    krw_t lti, boolean_t fatreader, boolean_t adding, zap_t **zapp)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   448
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   449
	zap_t *zap;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   450
	dmu_buf_t *db;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   451
	krw_t lt;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   452
	int err;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   453
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   454
	*zapp = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   455
12285
d736d62dcca2 6944833 Avoid prefetching dbufs in dmu_sync() path
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11165
diff changeset
   456
	err = dmu_buf_hold(os, obj, 0, NULL, &db, DMU_READ_NO_PREFETCH);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   457
	if (err)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   458
		return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   459
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   460
#ifdef ZFS_DEBUG
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   461
	{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   462
		dmu_object_info_t doi;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   463
		dmu_object_info_from_db(db, &doi);
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13524
diff changeset
   464
		ASSERT3U(DMU_OT_BYTESWAP(doi.doi_type), ==, DMU_BSWAP_ZAP);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   465
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   466
#endif
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   467
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   468
	zap = dmu_buf_get_user(db);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   469
	if (zap == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   470
		zap = mzap_open(os, obj, db);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   471
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   472
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   473
	 * We're checking zap_ismicro without the lock held, in order to
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   474
	 * tell what type of lock we want.  Once we have some sort of
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   475
	 * lock, see if it really is the right type.  In practice this
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   476
	 * can only be different if it was upgraded from micro to fat,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   477
	 * and micro wanted WRITER but fat only needs READER.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   478
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   479
	lt = (!zap->zap_ismicro && fatreader) ? RW_READER : lti;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   480
	rw_enter(&zap->zap_rwlock, lt);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   481
	if (lt != ((!zap->zap_ismicro && fatreader) ? RW_READER : lti)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   482
		/* it was upgraded, now we only need reader */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   483
		ASSERT(lt == RW_WRITER);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   484
		ASSERT(RW_READER ==
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   485
		    (!zap->zap_ismicro && fatreader) ? RW_READER : lti);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   486
		rw_downgrade(&zap->zap_rwlock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   487
		lt = RW_READER;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   488
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   489
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   490
	zap->zap_objset = os;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   491
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   492
	if (lt == RW_WRITER)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   493
		dmu_buf_will_dirty(db, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   494
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   495
	ASSERT3P(zap->zap_dbuf, ==, db);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   496
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   497
	ASSERT(!zap->zap_ismicro ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   498
	    zap->zap_m.zap_num_entries <= zap->zap_m.zap_num_chunks);
5384
8eba72d775e9 6623831 assertion failed in dmu_tx_willuse_space() from mzap_upgrade()
ahrens
parents: 5331
diff changeset
   499
	if (zap->zap_ismicro && tx && adding &&
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   500
	    zap->zap_m.zap_num_entries == zap->zap_m.zap_num_chunks) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   501
		uint64_t newsz = db->db_size + SPA_MINBLOCKSIZE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   502
		if (newsz > MZAP_MAX_BLKSZ) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   503
			dprintf("upgrading obj %llu: num_entries=%u\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   504
			    obj, zap->zap_m.zap_num_entries);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   505
			*zapp = zap;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   506
			return (mzap_upgrade(zapp, tx, 0));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   507
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   508
		err = dmu_object_set_blocksize(os, obj, newsz, 0, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   509
		ASSERT3U(err, ==, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   510
		zap->zap_m.zap_num_chunks =
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   511
		    db->db_size / MZAP_ENT_LEN - 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   512
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   513
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   514
	*zapp = zap;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   515
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   516
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   517
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   518
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   519
zap_unlockdir(zap_t *zap)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   520
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   521
	rw_exit(&zap->zap_rwlock);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   522
	dmu_buf_rele(zap->zap_dbuf, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   523
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   524
5497
913e555b2de5 6626801 deadbeef panic in fzap_update()
bonwick
parents: 5384
diff changeset
   525
static int
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   526
mzap_upgrade(zap_t **zapp, dmu_tx_t *tx, zap_flags_t flags)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   527
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   528
	mzap_phys_t *mzp;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   529
	int i, sz, nchunks;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   530
	int err = 0;
5497
913e555b2de5 6626801 deadbeef panic in fzap_update()
bonwick
parents: 5384
diff changeset
   531
	zap_t *zap = *zapp;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   532
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   533
	ASSERT(RW_WRITE_HELD(&zap->zap_rwlock));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   534
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   535
	sz = zap->zap_dbuf->db_size;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   536
	mzp = kmem_alloc(sz, KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   537
	bcopy(zap->zap_dbuf->db_data, mzp, sz);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   538
	nchunks = zap->zap_m.zap_num_chunks;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   539
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   540
	if (!flags) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   541
		err = dmu_object_set_blocksize(zap->zap_objset, zap->zap_object,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   542
		    1ULL << fzap_default_block_shift, 0, tx);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   543
		if (err) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   544
			kmem_free(mzp, sz);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   545
			return (err);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   546
		}
5497
913e555b2de5 6626801 deadbeef panic in fzap_update()
bonwick
parents: 5384
diff changeset
   547
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   548
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   549
	dprintf("upgrading obj=%llu with %u chunks\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   550
	    zap->zap_object, nchunks);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   551
	/* XXX destroy the avl later, so we can use the stored hash value */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   552
	mze_destroy(zap);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   553
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   554
	fzap_upgrade(zap, tx, flags);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   555
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   556
	for (i = 0; i < nchunks; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   557
		mzap_ent_phys_t *mze = &mzp->mz_chunk[i];
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   558
		zap_name_t *zn;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   559
		if (mze->mze_name[0] == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   560
			continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   561
		dprintf("adding %s=%llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   562
		    mze->mze_name, mze->mze_value);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   563
		zn = zap_name_alloc(zap, mze->mze_name, MT_EXACT);
5497
913e555b2de5 6626801 deadbeef panic in fzap_update()
bonwick
parents: 5384
diff changeset
   564
		err = fzap_add_cd(zn, 8, 1, &mze->mze_value, mze->mze_cd, tx);
913e555b2de5 6626801 deadbeef panic in fzap_update()
bonwick
parents: 5384
diff changeset
   565
		zap = zn->zn_zap;	/* fzap_add_cd() may change zap */
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   566
		zap_name_free(zn);
5497
913e555b2de5 6626801 deadbeef panic in fzap_update()
bonwick
parents: 5384
diff changeset
   567
		if (err)
913e555b2de5 6626801 deadbeef panic in fzap_update()
bonwick
parents: 5384
diff changeset
   568
			break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   569
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   570
	kmem_free(mzp, sz);
5497
913e555b2de5 6626801 deadbeef panic in fzap_update()
bonwick
parents: 5384
diff changeset
   571
	*zapp = zap;
913e555b2de5 6626801 deadbeef panic in fzap_update()
bonwick
parents: 5384
diff changeset
   572
	return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   573
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   574
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   575
static void
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   576
mzap_create_impl(objset_t *os, uint64_t obj, int normflags, zap_flags_t flags,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   577
    dmu_tx_t *tx)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   578
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   579
	dmu_buf_t *db;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   580
	mzap_phys_t *zp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   581
12285
d736d62dcca2 6944833 Avoid prefetching dbufs in dmu_sync() path
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11165
diff changeset
   582
	VERIFY(0 == dmu_buf_hold(os, obj, 0, FTAG, &db, DMU_READ_NO_PREFETCH));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   583
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   584
#ifdef ZFS_DEBUG
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   585
	{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   586
		dmu_object_info_t doi;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   587
		dmu_object_info_from_db(db, &doi);
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13524
diff changeset
   588
		ASSERT3U(DMU_OT_BYTESWAP(doi.doi_type), ==, DMU_BSWAP_ZAP);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   589
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   590
#endif
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   591
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   592
	dmu_buf_will_dirty(db, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   593
	zp = db->db_data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   594
	zp->mz_block_type = ZBT_MICRO;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   595
	zp->mz_salt = ((uintptr_t)db ^ (uintptr_t)tx ^ (obj << 1)) | 1ULL;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   596
	zp->mz_normflags = normflags;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   597
	dmu_buf_rele(db, FTAG);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   598
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   599
	if (flags != 0) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   600
		zap_t *zap;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   601
		/* Only fat zap supports flags; upgrade immediately. */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   602
		VERIFY(0 == zap_lockdir(os, obj, tx, RW_WRITER,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   603
		    B_FALSE, B_FALSE, &zap));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   604
		VERIFY3U(0, ==, mzap_upgrade(&zap, tx, flags));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   605
		zap_unlockdir(zap);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   606
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   607
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   608
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   609
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   610
zap_create_claim(objset_t *os, uint64_t obj, dmu_object_type_t ot,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   611
    dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   612
{
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   613
	return (zap_create_claim_norm(os, obj,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   614
	    0, ot, bonustype, bonuslen, tx));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   615
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   616
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   617
int
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   618
zap_create_claim_norm(objset_t *os, uint64_t obj, int normflags,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   619
    dmu_object_type_t ot,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   620
    dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   621
{
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   622
	int err;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   623
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   624
	err = dmu_object_claim(os, obj, ot, 0, bonustype, bonuslen, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   625
	if (err != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   626
		return (err);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   627
	mzap_create_impl(os, obj, normflags, 0, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   628
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   629
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   630
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   631
uint64_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   632
zap_create(objset_t *os, dmu_object_type_t ot,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   633
    dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   634
{
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   635
	return (zap_create_norm(os, 0, ot, bonustype, bonuslen, tx));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   636
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   637
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   638
uint64_t
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   639
zap_create_norm(objset_t *os, int normflags, dmu_object_type_t ot,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   640
    dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   641
{
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   642
	uint64_t obj = dmu_object_alloc(os, ot, 0, bonustype, bonuslen, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   643
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   644
	mzap_create_impl(os, obj, normflags, 0, tx);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   645
	return (obj);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   646
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   647
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   648
uint64_t
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   649
zap_create_flags(objset_t *os, int normflags, zap_flags_t flags,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   650
    dmu_object_type_t ot, int leaf_blockshift, int indirect_blockshift,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   651
    dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   652
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   653
	uint64_t obj = dmu_object_alloc(os, ot, 0, bonustype, bonuslen, tx);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   654
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   655
	ASSERT(leaf_blockshift >= SPA_MINBLOCKSHIFT &&
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   656
	    leaf_blockshift <= SPA_MAXBLOCKSHIFT &&
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   657
	    indirect_blockshift >= SPA_MINBLOCKSHIFT &&
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   658
	    indirect_blockshift <= SPA_MAXBLOCKSHIFT);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   659
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   660
	VERIFY(dmu_object_set_blocksize(os, obj,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   661
	    1ULL << leaf_blockshift, indirect_blockshift, tx) == 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   662
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   663
	mzap_create_impl(os, obj, normflags, flags, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   664
	return (obj);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   665
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   666
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   667
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   668
zap_destroy(objset_t *os, uint64_t zapobj, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   669
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   670
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   671
	 * dmu_object_free will free the object number and free the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   672
	 * data.  Freeing the data will cause our pageout function to be
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   673
	 * called, which will destroy our data (zap_leaf_t's and zap_t).
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   674
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   675
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   676
	return (dmu_object_free(os, zapobj, tx));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   677
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   678
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   679
_NOTE(ARGSUSED(0))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   680
void
2641
967ea438b194 6462174 zap_update() likes to return 0
ahrens
parents: 1544
diff changeset
   681
zap_evict(dmu_buf_t *db, void *vzap)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   682
{
2641
967ea438b194 6462174 zap_update() likes to return 0
ahrens
parents: 1544
diff changeset
   683
	zap_t *zap = vzap;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   684
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   685
	rw_destroy(&zap->zap_rwlock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   686
1491
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   687
	if (zap->zap_ismicro)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   688
		mze_destroy(zap);
4831
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 2856
diff changeset
   689
	else
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 2856
diff changeset
   690
		mutex_destroy(&zap->zap_f.zap_num_entries_mtx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   691
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   692
	kmem_free(zap, sizeof (zap_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   693
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   694
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   695
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   696
zap_count(objset_t *os, uint64_t zapobj, uint64_t *count)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   697
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   698
	zap_t *zap;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   699
	int err;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   700
5384
8eba72d775e9 6623831 assertion failed in dmu_tx_willuse_space() from mzap_upgrade()
ahrens
parents: 5331
diff changeset
   701
	err = zap_lockdir(os, zapobj, NULL, RW_READER, TRUE, FALSE, &zap);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   702
	if (err)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   703
		return (err);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   704
	if (!zap->zap_ismicro) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   705
		err = fzap_count(zap, count);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   706
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   707
		*count = zap->zap_m.zap_num_entries;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   708
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   709
	zap_unlockdir(zap);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   710
	return (err);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   711
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   712
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   713
/*
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   714
 * zn may be NULL; if not specified, it will be computed if needed.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   715
 * See also the comment above zap_entry_normalization_conflict().
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   716
 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   717
static boolean_t
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   718
mzap_normalization_conflict(zap_t *zap, zap_name_t *zn, mzap_ent_t *mze)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   719
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   720
	mzap_ent_t *other;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   721
	int direction = AVL_BEFORE;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   722
	boolean_t allocdzn = B_FALSE;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   723
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   724
	if (zap->zap_normflags == 0)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   725
		return (B_FALSE);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   726
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   727
again:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   728
	for (other = avl_walk(&zap->zap_m.zap_avl, mze, direction);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   729
	    other && other->mze_hash == mze->mze_hash;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   730
	    other = avl_walk(&zap->zap_m.zap_avl, other, direction)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   731
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   732
		if (zn == NULL) {
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
   733
			zn = zap_name_alloc(zap, MZE_PHYS(zap, mze)->mze_name,
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   734
			    MT_FIRST);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   735
			allocdzn = B_TRUE;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   736
		}
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
   737
		if (zap_match(zn, MZE_PHYS(zap, other)->mze_name)) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   738
			if (allocdzn)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   739
				zap_name_free(zn);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   740
			return (B_TRUE);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   741
		}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   742
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   743
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   744
	if (direction == AVL_BEFORE) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   745
		direction = AVL_AFTER;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   746
		goto again;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   747
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   748
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   749
	if (allocdzn)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   750
		zap_name_free(zn);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   751
	return (B_FALSE);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   752
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   753
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   754
/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   755
 * Routines for manipulating attributes.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   756
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   757
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   758
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   759
zap_lookup(objset_t *os, uint64_t zapobj, const char *name,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   760
    uint64_t integer_size, uint64_t num_integers, void *buf)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   761
{
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   762
	return (zap_lookup_norm(os, zapobj, name, integer_size,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   763
	    num_integers, buf, MT_EXACT, NULL, 0, NULL));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   764
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   765
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   766
int
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   767
zap_lookup_norm(objset_t *os, uint64_t zapobj, const char *name,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   768
    uint64_t integer_size, uint64_t num_integers, void *buf,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   769
    matchtype_t mt, char *realname, int rn_len,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   770
    boolean_t *ncp)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   771
{
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   772
	zap_t *zap;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   773
	int err;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   774
	mzap_ent_t *mze;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   775
	zap_name_t *zn;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   776
5384
8eba72d775e9 6623831 assertion failed in dmu_tx_willuse_space() from mzap_upgrade()
ahrens
parents: 5331
diff changeset
   777
	err = zap_lockdir(os, zapobj, NULL, RW_READER, TRUE, FALSE, &zap);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   778
	if (err)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   779
		return (err);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   780
	zn = zap_name_alloc(zap, name, mt);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   781
	if (zn == NULL) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   782
		zap_unlockdir(zap);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   783
		return (ENOTSUP);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   784
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   785
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   786
	if (!zap->zap_ismicro) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   787
		err = fzap_lookup(zn, integer_size, num_integers, buf,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   788
		    realname, rn_len, ncp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   789
	} else {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   790
		mze = mze_find(zn);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   791
		if (mze == NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   792
			err = ENOENT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   793
		} else {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   794
			if (num_integers < 1) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   795
				err = EOVERFLOW;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   796
			} else if (integer_size != 8) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   797
				err = EINVAL;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   798
			} else {
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
   799
				*(uint64_t *)buf =
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
   800
				    MZE_PHYS(zap, mze)->mze_value;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   801
				(void) strlcpy(realname,
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
   802
				    MZE_PHYS(zap, mze)->mze_name, rn_len);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   803
				if (ncp) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   804
					*ncp = mzap_normalization_conflict(zap,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   805
					    zn, mze);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   806
				}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   807
			}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   808
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   809
	}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   810
	zap_name_free(zn);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   811
	zap_unlockdir(zap);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   812
	return (err);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   813
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   814
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   815
int
12450
c77e20e4e046 6938089 dedup-induced latency causes FC initiator logouts/FC port resets
George Wilson <George.Wilson@Sun.COM>
parents: 12296
diff changeset
   816
zap_prefetch_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
c77e20e4e046 6938089 dedup-induced latency causes FC initiator logouts/FC port resets
George Wilson <George.Wilson@Sun.COM>
parents: 12296
diff changeset
   817
    int key_numints)
c77e20e4e046 6938089 dedup-induced latency causes FC initiator logouts/FC port resets
George Wilson <George.Wilson@Sun.COM>
parents: 12296
diff changeset
   818
{
c77e20e4e046 6938089 dedup-induced latency causes FC initiator logouts/FC port resets
George Wilson <George.Wilson@Sun.COM>
parents: 12296
diff changeset
   819
	zap_t *zap;
c77e20e4e046 6938089 dedup-induced latency causes FC initiator logouts/FC port resets
George Wilson <George.Wilson@Sun.COM>
parents: 12296
diff changeset
   820
	int err;
c77e20e4e046 6938089 dedup-induced latency causes FC initiator logouts/FC port resets
George Wilson <George.Wilson@Sun.COM>
parents: 12296
diff changeset
   821
	zap_name_t *zn;
c77e20e4e046 6938089 dedup-induced latency causes FC initiator logouts/FC port resets
George Wilson <George.Wilson@Sun.COM>
parents: 12296
diff changeset
   822
c77e20e4e046 6938089 dedup-induced latency causes FC initiator logouts/FC port resets
George Wilson <George.Wilson@Sun.COM>
parents: 12296
diff changeset
   823
	err = zap_lockdir(os, zapobj, NULL, RW_READER, TRUE, FALSE, &zap);
c77e20e4e046 6938089 dedup-induced latency causes FC initiator logouts/FC port resets
George Wilson <George.Wilson@Sun.COM>
parents: 12296
diff changeset
   824
	if (err)
c77e20e4e046 6938089 dedup-induced latency causes FC initiator logouts/FC port resets
George Wilson <George.Wilson@Sun.COM>
parents: 12296
diff changeset
   825
		return (err);
c77e20e4e046 6938089 dedup-induced latency causes FC initiator logouts/FC port resets
George Wilson <George.Wilson@Sun.COM>
parents: 12296
diff changeset
   826
	zn = zap_name_alloc_uint64(zap, key, key_numints);
c77e20e4e046 6938089 dedup-induced latency causes FC initiator logouts/FC port resets
George Wilson <George.Wilson@Sun.COM>
parents: 12296
diff changeset
   827
	if (zn == NULL) {
c77e20e4e046 6938089 dedup-induced latency causes FC initiator logouts/FC port resets
George Wilson <George.Wilson@Sun.COM>
parents: 12296
diff changeset
   828
		zap_unlockdir(zap);
c77e20e4e046 6938089 dedup-induced latency causes FC initiator logouts/FC port resets
George Wilson <George.Wilson@Sun.COM>
parents: 12296
diff changeset
   829
		return (ENOTSUP);
c77e20e4e046 6938089 dedup-induced latency causes FC initiator logouts/FC port resets
George Wilson <George.Wilson@Sun.COM>
parents: 12296
diff changeset
   830
	}
c77e20e4e046 6938089 dedup-induced latency causes FC initiator logouts/FC port resets
George Wilson <George.Wilson@Sun.COM>
parents: 12296
diff changeset
   831
c77e20e4e046 6938089 dedup-induced latency causes FC initiator logouts/FC port resets
George Wilson <George.Wilson@Sun.COM>
parents: 12296
diff changeset
   832
	fzap_prefetch(zn);
c77e20e4e046 6938089 dedup-induced latency causes FC initiator logouts/FC port resets
George Wilson <George.Wilson@Sun.COM>
parents: 12296
diff changeset
   833
	zap_name_free(zn);
c77e20e4e046 6938089 dedup-induced latency causes FC initiator logouts/FC port resets
George Wilson <George.Wilson@Sun.COM>
parents: 12296
diff changeset
   834
	zap_unlockdir(zap);
c77e20e4e046 6938089 dedup-induced latency causes FC initiator logouts/FC port resets
George Wilson <George.Wilson@Sun.COM>
parents: 12296
diff changeset
   835
	return (err);
c77e20e4e046 6938089 dedup-induced latency causes FC initiator logouts/FC port resets
George Wilson <George.Wilson@Sun.COM>
parents: 12296
diff changeset
   836
}
c77e20e4e046 6938089 dedup-induced latency causes FC initiator logouts/FC port resets
George Wilson <George.Wilson@Sun.COM>
parents: 12296
diff changeset
   837
c77e20e4e046 6938089 dedup-induced latency causes FC initiator logouts/FC port resets
George Wilson <George.Wilson@Sun.COM>
parents: 12296
diff changeset
   838
int
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   839
zap_lookup_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   840
    int key_numints, uint64_t integer_size, uint64_t num_integers, void *buf)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   841
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   842
	zap_t *zap;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   843
	int err;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   844
	zap_name_t *zn;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   845
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   846
	err = zap_lockdir(os, zapobj, NULL, RW_READER, TRUE, FALSE, &zap);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   847
	if (err)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   848
		return (err);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   849
	zn = zap_name_alloc_uint64(zap, key, key_numints);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   850
	if (zn == NULL) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   851
		zap_unlockdir(zap);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   852
		return (ENOTSUP);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   853
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   854
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   855
	err = fzap_lookup(zn, integer_size, num_integers, buf,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   856
	    NULL, 0, NULL);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   857
	zap_name_free(zn);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   858
	zap_unlockdir(zap);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   859
	return (err);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   860
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   861
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   862
int
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10922
diff changeset
   863
zap_contains(objset_t *os, uint64_t zapobj, const char *name)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10922
diff changeset
   864
{
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10922
diff changeset
   865
	int err = (zap_lookup_norm(os, zapobj, name, 0,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10922
diff changeset
   866
	    0, NULL, MT_EXACT, NULL, 0, NULL));
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10922
diff changeset
   867
	if (err == EOVERFLOW || err == EINVAL)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10922
diff changeset
   868
		err = 0; /* found, but skipped reading the value */
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10922
diff changeset
   869
	return (err);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10922
diff changeset
   870
}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10922
diff changeset
   871
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10922
diff changeset
   872
int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   873
zap_length(objset_t *os, uint64_t zapobj, const char *name,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   874
    uint64_t *integer_size, uint64_t *num_integers)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   875
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   876
	zap_t *zap;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   877
	int err;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   878
	mzap_ent_t *mze;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   879
	zap_name_t *zn;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   880
5384
8eba72d775e9 6623831 assertion failed in dmu_tx_willuse_space() from mzap_upgrade()
ahrens
parents: 5331
diff changeset
   881
	err = zap_lockdir(os, zapobj, NULL, RW_READER, TRUE, FALSE, &zap);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   882
	if (err)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   883
		return (err);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   884
	zn = zap_name_alloc(zap, name, MT_EXACT);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   885
	if (zn == NULL) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   886
		zap_unlockdir(zap);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   887
		return (ENOTSUP);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   888
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   889
	if (!zap->zap_ismicro) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   890
		err = fzap_length(zn, integer_size, num_integers);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   891
	} else {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   892
		mze = mze_find(zn);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   893
		if (mze == NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   894
			err = ENOENT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   895
		} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   896
			if (integer_size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   897
				*integer_size = 8;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   898
			if (num_integers)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   899
				*num_integers = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   900
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   901
	}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   902
	zap_name_free(zn);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   903
	zap_unlockdir(zap);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   904
	return (err);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   905
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   906
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   907
int
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   908
zap_length_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   909
    int key_numints, uint64_t *integer_size, uint64_t *num_integers)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   910
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   911
	zap_t *zap;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   912
	int err;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   913
	zap_name_t *zn;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   914
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   915
	err = zap_lockdir(os, zapobj, NULL, RW_READER, TRUE, FALSE, &zap);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   916
	if (err)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   917
		return (err);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   918
	zn = zap_name_alloc_uint64(zap, key, key_numints);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   919
	if (zn == NULL) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   920
		zap_unlockdir(zap);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   921
		return (ENOTSUP);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   922
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   923
	err = fzap_length(zn, integer_size, num_integers);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   924
	zap_name_free(zn);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   925
	zap_unlockdir(zap);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   926
	return (err);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   927
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   928
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   929
static void
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   930
mzap_addent(zap_name_t *zn, uint64_t value)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   931
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   932
	int i;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   933
	zap_t *zap = zn->zn_zap;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   934
	int start = zap->zap_m.zap_alloc_next;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   935
	uint32_t cd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   936
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   937
	ASSERT(RW_WRITE_HELD(&zap->zap_rwlock));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   938
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   939
#ifdef ZFS_DEBUG
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   940
	for (i = 0; i < zap->zap_m.zap_num_chunks; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   941
		mzap_ent_phys_t *mze = &zap->zap_m.zap_phys->mz_chunk[i];
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   942
		ASSERT(strcmp(zn->zn_key_orig, mze->mze_name) != 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   943
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   944
#endif
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   945
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   946
	cd = mze_find_unused_cd(zap, zn->zn_hash);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   947
	/* given the limited size of the microzap, this can't happen */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   948
	ASSERT(cd < zap_maxcd(zap));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   949
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   950
again:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   951
	for (i = start; i < zap->zap_m.zap_num_chunks; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   952
		mzap_ent_phys_t *mze = &zap->zap_m.zap_phys->mz_chunk[i];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   953
		if (mze->mze_name[0] == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   954
			mze->mze_value = value;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   955
			mze->mze_cd = cd;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   956
			(void) strcpy(mze->mze_name, zn->zn_key_orig);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   957
			zap->zap_m.zap_num_entries++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   958
			zap->zap_m.zap_alloc_next = i+1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   959
			if (zap->zap_m.zap_alloc_next ==
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   960
			    zap->zap_m.zap_num_chunks)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   961
				zap->zap_m.zap_alloc_next = 0;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
   962
			mze_insert(zap, i, zn->zn_hash);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   963
			return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   964
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   965
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   966
	if (start != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   967
		start = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   968
		goto again;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   969
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   970
	ASSERT(!"out of entries!");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   971
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   972
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   973
int
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   974
zap_add(objset_t *os, uint64_t zapobj, const char *key,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   975
    int integer_size, uint64_t num_integers,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   976
    const void *val, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   977
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   978
	zap_t *zap;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   979
	int err;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   980
	mzap_ent_t *mze;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   981
	const uint64_t *intval = val;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   982
	zap_name_t *zn;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   983
5384
8eba72d775e9 6623831 assertion failed in dmu_tx_willuse_space() from mzap_upgrade()
ahrens
parents: 5331
diff changeset
   984
	err = zap_lockdir(os, zapobj, tx, RW_WRITER, TRUE, TRUE, &zap);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   985
	if (err)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   986
		return (err);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   987
	zn = zap_name_alloc(zap, key, MT_EXACT);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   988
	if (zn == NULL) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   989
		zap_unlockdir(zap);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   990
		return (ENOTSUP);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   991
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   992
	if (!zap->zap_ismicro) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   993
		err = fzap_add(zn, integer_size, num_integers, val, tx);
5497
913e555b2de5 6626801 deadbeef panic in fzap_update()
bonwick
parents: 5384
diff changeset
   994
		zap = zn->zn_zap;	/* fzap_add() may change zap */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   995
	} else if (integer_size != 8 || num_integers != 1 ||
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   996
	    strlen(key) >= MZAP_NAME_LEN) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   997
		err = mzap_upgrade(&zn->zn_zap, tx, 0);
5497
913e555b2de5 6626801 deadbeef panic in fzap_update()
bonwick
parents: 5384
diff changeset
   998
		if (err == 0)
913e555b2de5 6626801 deadbeef panic in fzap_update()
bonwick
parents: 5384
diff changeset
   999
			err = fzap_add(zn, integer_size, num_integers, val, tx);
913e555b2de5 6626801 deadbeef panic in fzap_update()
bonwick
parents: 5384
diff changeset
  1000
		zap = zn->zn_zap;	/* fzap_add() may change zap */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1001
	} else {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
  1002
		mze = mze_find(zn);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1003
		if (mze != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1004
			err = EEXIST;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1005
		} else {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
  1006
			mzap_addent(zn, *intval);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1007
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1008
	}
5497
913e555b2de5 6626801 deadbeef panic in fzap_update()
bonwick
parents: 5384
diff changeset
  1009
	ASSERT(zap == zn->zn_zap);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
  1010
	zap_name_free(zn);
5497
913e555b2de5 6626801 deadbeef panic in fzap_update()
bonwick
parents: 5384
diff changeset
  1011
	if (zap != NULL)	/* may be NULL if fzap_add() failed */
913e555b2de5 6626801 deadbeef panic in fzap_update()
bonwick
parents: 5384
diff changeset
  1012
		zap_unlockdir(zap);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1013
	return (err);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1014
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1015
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1016
int
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1017
zap_add_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1018
    int key_numints, int integer_size, uint64_t num_integers,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1019
    const void *val, dmu_tx_t *tx)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1020
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1021
	zap_t *zap;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1022
	int err;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1023
	zap_name_t *zn;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1024
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1025
	err = zap_lockdir(os, zapobj, tx, RW_WRITER, TRUE, TRUE, &zap);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1026
	if (err)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1027
		return (err);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1028
	zn = zap_name_alloc_uint64(zap, key, key_numints);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1029
	if (zn == NULL) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1030
		zap_unlockdir(zap);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1031
		return (ENOTSUP);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1032
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1033
	err = fzap_add(zn, integer_size, num_integers, val, tx);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1034
	zap = zn->zn_zap;	/* fzap_add() may change zap */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1035
	zap_name_free(zn);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1036
	if (zap != NULL)	/* may be NULL if fzap_add() failed */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1037
		zap_unlockdir(zap);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1038
	return (err);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1039
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1040
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1041
int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1042
zap_update(objset_t *os, uint64_t zapobj, const char *name,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1043
    int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1044
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1045
	zap_t *zap;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1046
	mzap_ent_t *mze;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1047
	uint64_t oldval;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1048
	const uint64_t *intval = val;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
  1049
	zap_name_t *zn;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1050
	int err;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1051
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1052
#ifdef ZFS_DEBUG
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1053
	/*
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1054
	 * If there is an old value, it shouldn't change across the
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1055
	 * lockdir (eg, due to bprewrite's xlation).
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1056
	 */
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1057
	if (integer_size == 8 && num_integers == 1)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1058
		(void) zap_lookup(os, zapobj, name, 8, 1, &oldval);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1059
#endif
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1060
5384
8eba72d775e9 6623831 assertion failed in dmu_tx_willuse_space() from mzap_upgrade()
ahrens
parents: 5331
diff changeset
  1061
	err = zap_lockdir(os, zapobj, tx, RW_WRITER, TRUE, TRUE, &zap);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1062
	if (err)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1063
		return (err);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
  1064
	zn = zap_name_alloc(zap, name, MT_EXACT);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
  1065
	if (zn == NULL) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
  1066
		zap_unlockdir(zap);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
  1067
		return (ENOTSUP);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
  1068
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1069
	if (!zap->zap_ismicro) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
  1070
		err = fzap_update(zn, integer_size, num_integers, val, tx);
5497
913e555b2de5 6626801 deadbeef panic in fzap_update()
bonwick
parents: 5384
diff changeset
  1071
		zap = zn->zn_zap;	/* fzap_update() may change zap */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1072
	} else if (integer_size != 8 || num_integers != 1 ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1073
	    strlen(name) >= MZAP_NAME_LEN) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1074
		dprintf("upgrading obj %llu: intsz=%u numint=%llu name=%s\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1075
		    zapobj, integer_size, num_integers, name);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1076
		err = mzap_upgrade(&zn->zn_zap, tx, 0);
5497
913e555b2de5 6626801 deadbeef panic in fzap_update()
bonwick
parents: 5384
diff changeset
  1077
		if (err == 0)
913e555b2de5 6626801 deadbeef panic in fzap_update()
bonwick
parents: 5384
diff changeset
  1078
			err = fzap_update(zn, integer_size, num_integers,
913e555b2de5 6626801 deadbeef panic in fzap_update()
bonwick
parents: 5384
diff changeset
  1079
			    val, tx);
913e555b2de5 6626801 deadbeef panic in fzap_update()
bonwick
parents: 5384
diff changeset
  1080
		zap = zn->zn_zap;	/* fzap_update() may change zap */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1081
	} else {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
  1082
		mze = mze_find(zn);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1083
		if (mze != NULL) {
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1084
			ASSERT3U(MZE_PHYS(zap, mze)->mze_value, ==, oldval);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1085
			MZE_PHYS(zap, mze)->mze_value = *intval;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1086
		} else {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
  1087
			mzap_addent(zn, *intval);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1088
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1089
	}
5497
913e555b2de5 6626801 deadbeef panic in fzap_update()
bonwick
parents: 5384
diff changeset
  1090
	ASSERT(zap == zn->zn_zap);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
  1091
	zap_name_free(zn);
5497
913e555b2de5 6626801 deadbeef panic in fzap_update()
bonwick
parents: 5384
diff changeset
  1092
	if (zap != NULL)	/* may be NULL if fzap_upgrade() failed */
913e555b2de5 6626801 deadbeef panic in fzap_update()
bonwick
parents: 5384
diff changeset
  1093
		zap_unlockdir(zap);
2641
967ea438b194 6462174 zap_update() likes to return 0
ahrens
parents: 1544
diff changeset
  1094
	return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1095
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1096
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1097
int
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1098
zap_update_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1099
    int key_numints,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1100
    int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1101
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1102
	zap_t *zap;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1103
	zap_name_t *zn;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1104
	int err;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1105
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1106
	err = zap_lockdir(os, zapobj, tx, RW_WRITER, TRUE, TRUE, &zap);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1107
	if (err)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1108
		return (err);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1109
	zn = zap_name_alloc_uint64(zap, key, key_numints);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1110
	if (zn == NULL) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1111
		zap_unlockdir(zap);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1112
		return (ENOTSUP);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1113
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1114
	err = fzap_update(zn, integer_size, num_integers, val, tx);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1115
	zap = zn->zn_zap;	/* fzap_update() may change zap */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1116
	zap_name_free(zn);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1117
	if (zap != NULL)	/* may be NULL if fzap_upgrade() failed */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1118
		zap_unlockdir(zap);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1119
	return (err);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1120
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1121
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1122
int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1123
zap_remove(objset_t *os, uint64_t zapobj, const char *name, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1124
{
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
  1125
	return (zap_remove_norm(os, zapobj, name, MT_EXACT, tx));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
  1126
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
  1127
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
  1128
int
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
  1129
zap_remove_norm(objset_t *os, uint64_t zapobj, const char *name,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
  1130
    matchtype_t mt, dmu_tx_t *tx)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
  1131
{
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1132
	zap_t *zap;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1133
	int err;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1134
	mzap_ent_t *mze;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
  1135
	zap_name_t *zn;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1136
5384
8eba72d775e9 6623831 assertion failed in dmu_tx_willuse_space() from mzap_upgrade()
ahrens
parents: 5331
diff changeset
  1137
	err = zap_lockdir(os, zapobj, tx, RW_WRITER, TRUE, FALSE, &zap);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1138
	if (err)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1139
		return (err);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
  1140
	zn = zap_name_alloc(zap, name, mt);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
  1141
	if (zn == NULL) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
  1142
		zap_unlockdir(zap);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
  1143
		return (ENOTSUP);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
  1144
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1145
	if (!zap->zap_ismicro) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
  1146
		err = fzap_remove(zn, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1147
	} else {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
  1148
		mze = mze_find(zn);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1149
		if (mze == NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1150
			err = ENOENT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1151
		} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1152
			zap->zap_m.zap_num_entries--;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1153
			bzero(&zap->zap_m.zap_phys->mz_chunk[mze->mze_chunkid],
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1154
			    sizeof (mzap_ent_phys_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1155
			mze_remove(zap, mze);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1156
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1157
	}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
  1158
	zap_name_free(zn);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1159
	zap_unlockdir(zap);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1160
	return (err);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1161
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1162
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1163
int
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1164
zap_remove_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1165
    int key_numints, dmu_tx_t *tx)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1166
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1167
	zap_t *zap;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1168
	int err;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1169
	zap_name_t *zn;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1170
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1171
	err = zap_lockdir(os, zapobj, tx, RW_WRITER, TRUE, FALSE, &zap);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1172
	if (err)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1173
		return (err);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1174
	zn = zap_name_alloc_uint64(zap, key, key_numints);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1175
	if (zn == NULL) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1176
		zap_unlockdir(zap);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1177
		return (ENOTSUP);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1178
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1179
	err = fzap_remove(zn, tx);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1180
	zap_name_free(zn);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1181
	zap_unlockdir(zap);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1182
	return (err);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1183
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1184
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1185
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1186
 * Routines for iterating over the attributes.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1187
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1188
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1189
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1190
zap_cursor_init_serialized(zap_cursor_t *zc, objset_t *os, uint64_t zapobj,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1191
    uint64_t serialized)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1192
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1193
	zc->zc_objset = os;
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1194
	zc->zc_zap = NULL;
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1195
	zc->zc_leaf = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1196
	zc->zc_zapobj = zapobj;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1197
	zc->zc_serialized = serialized;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1198
	zc->zc_hash = 0;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1199
	zc->zc_cd = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1200
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1201
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1202
void
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1203
zap_cursor_init(zap_cursor_t *zc, objset_t *os, uint64_t zapobj)
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1204
{
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1205
	zap_cursor_init_serialized(zc, os, zapobj, 0);
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1206
}
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1207
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1208
void
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1209
zap_cursor_fini(zap_cursor_t *zc)
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1210
{
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1211
	if (zc->zc_zap) {
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1212
		rw_enter(&zc->zc_zap->zap_rwlock, RW_READER);
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1213
		zap_unlockdir(zc->zc_zap);
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1214
		zc->zc_zap = NULL;
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1215
	}
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1216
	if (zc->zc_leaf) {
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1217
		rw_enter(&zc->zc_leaf->l_rwlock, RW_READER);
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1218
		zap_put_leaf(zc->zc_leaf);
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1219
		zc->zc_leaf = NULL;
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1220
	}
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1221
	zc->zc_objset = NULL;
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1222
}
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1223
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1224
uint64_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1225
zap_cursor_serialize(zap_cursor_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1226
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1227
	if (zc->zc_hash == -1ULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1228
		return (-1ULL);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1229
	if (zc->zc_zap == NULL)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1230
		return (zc->zc_serialized);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1231
	ASSERT((zc->zc_hash & zap_maxcd(zc->zc_zap)) == 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1232
	ASSERT(zc->zc_cd < zap_maxcd(zc->zc_zap));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1233
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1234
	/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1235
	 * We want to keep the high 32 bits of the cursor zero if we can, so
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1236
	 * that 32-bit programs can access this.  So usually use a small
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1237
	 * (28-bit) hash value so we can fit 4 bits of cd into the low 32-bits
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1238
	 * of the cursor.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1239
	 *
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1240
	 * [ collision differentiator | zap_hashbits()-bit hash value ]
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1241
	 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1242
	return ((zc->zc_hash >> (64 - zap_hashbits(zc->zc_zap))) |
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1243
	    ((uint64_t)zc->zc_cd << zap_hashbits(zc->zc_zap)));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1244
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1245
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1246
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1247
zap_cursor_retrieve(zap_cursor_t *zc, zap_attribute_t *za)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1248
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1249
	int err;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1250
	avl_index_t idx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1251
	mzap_ent_t mze_tofind;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1252
	mzap_ent_t *mze;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1253
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1254
	if (zc->zc_hash == -1ULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1255
		return (ENOENT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1256
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1257
	if (zc->zc_zap == NULL) {
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1258
		int hb;
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1259
		err = zap_lockdir(zc->zc_objset, zc->zc_zapobj, NULL,
5384
8eba72d775e9 6623831 assertion failed in dmu_tx_willuse_space() from mzap_upgrade()
ahrens
parents: 5331
diff changeset
  1260
		    RW_READER, TRUE, FALSE, &zc->zc_zap);
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1261
		if (err)
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1262
			return (err);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1263
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1264
		/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1265
		 * To support zap_cursor_init_serialized, advance, retrieve,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1266
		 * we must add to the existing zc_cd, which may already
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1267
		 * be 1 due to the zap_cursor_advance.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1268
		 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1269
		ASSERT(zc->zc_hash == 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1270
		hb = zap_hashbits(zc->zc_zap);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1271
		zc->zc_hash = zc->zc_serialized << (64 - hb);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1272
		zc->zc_cd += zc->zc_serialized >> hb;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1273
		if (zc->zc_cd >= zap_maxcd(zc->zc_zap)) /* corrupt serialized */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1274
			zc->zc_cd = 0;
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1275
	} else {
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1276
		rw_enter(&zc->zc_zap->zap_rwlock, RW_READER);
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1277
	}
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1278
	if (!zc->zc_zap->zap_ismicro) {
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1279
		err = fzap_cursor_retrieve(zc->zc_zap, zc, za);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1280
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1281
		err = ENOENT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1282
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1283
		mze_tofind.mze_hash = zc->zc_hash;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1284
		mze_tofind.mze_cd = zc->zc_cd;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1285
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1286
		mze = avl_find(&zc->zc_zap->zap_m.zap_avl, &mze_tofind, &idx);
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1287
		if (mze == NULL) {
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1288
			mze = avl_nearest(&zc->zc_zap->zap_m.zap_avl,
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1289
			    idx, AVL_AFTER);
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1290
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1291
		if (mze) {
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1292
			mzap_ent_phys_t *mzep = MZE_PHYS(zc->zc_zap, mze);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1293
			ASSERT3U(mze->mze_cd, ==, mzep->mze_cd);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
  1294
			za->za_normalization_conflict =
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
  1295
			    mzap_normalization_conflict(zc->zc_zap, NULL, mze);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1296
			za->za_integer_length = 8;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1297
			za->za_num_integers = 1;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1298
			za->za_first_integer = mzep->mze_value;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1299
			(void) strcpy(za->za_name, mzep->mze_name);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1300
			zc->zc_hash = mze->mze_hash;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1301
			zc->zc_cd = mze->mze_cd;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1302
			err = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1303
		} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1304
			zc->zc_hash = -1ULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1305
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1306
	}
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1307
	rw_exit(&zc->zc_zap->zap_rwlock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1308
	return (err);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1309
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1310
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1311
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1312
zap_cursor_advance(zap_cursor_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1313
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1314
	if (zc->zc_hash == -1ULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1315
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1316
	zc->zc_cd++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1317
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1318
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1319
int
10612
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9873
diff changeset
  1320
zap_cursor_move_to_key(zap_cursor_t *zc, const char *name, matchtype_t mt)
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9873
diff changeset
  1321
{
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9873
diff changeset
  1322
	int err = 0;
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9873
diff changeset
  1323
	mzap_ent_t *mze;
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9873
diff changeset
  1324
	zap_name_t *zn;
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9873
diff changeset
  1325
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9873
diff changeset
  1326
	if (zc->zc_zap == NULL) {
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9873
diff changeset
  1327
		err = zap_lockdir(zc->zc_objset, zc->zc_zapobj, NULL,
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9873
diff changeset
  1328
		    RW_READER, TRUE, FALSE, &zc->zc_zap);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9873
diff changeset
  1329
		if (err)
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9873
diff changeset
  1330
			return (err);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9873
diff changeset
  1331
	} else {
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9873
diff changeset
  1332
		rw_enter(&zc->zc_zap->zap_rwlock, RW_READER);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9873
diff changeset
  1333
	}
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9873
diff changeset
  1334
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9873
diff changeset
  1335
	zn = zap_name_alloc(zc->zc_zap, name, mt);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9873
diff changeset
  1336
	if (zn == NULL) {
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9873
diff changeset
  1337
		rw_exit(&zc->zc_zap->zap_rwlock);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9873
diff changeset
  1338
		return (ENOTSUP);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9873
diff changeset
  1339
	}
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9873
diff changeset
  1340
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9873
diff changeset
  1341
	if (!zc->zc_zap->zap_ismicro) {
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9873
diff changeset
  1342
		err = fzap_cursor_move_to_key(zc, zn);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9873
diff changeset
  1343
	} else {
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9873
diff changeset
  1344
		mze = mze_find(zn);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9873
diff changeset
  1345
		if (mze == NULL) {
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9873
diff changeset
  1346
			err = ENOENT;
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9873
diff changeset
  1347
			goto out;
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9873
diff changeset
  1348
		}
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9873
diff changeset
  1349
		zc->zc_hash = mze->mze_hash;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1350
		zc->zc_cd = mze->mze_cd;
10612
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9873
diff changeset
  1351
	}
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9873
diff changeset
  1352
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9873
diff changeset
  1353
out:
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9873
diff changeset
  1354
	zap_name_free(zn);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9873
diff changeset
  1355
	rw_exit(&zc->zc_zap->zap_rwlock);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9873
diff changeset
  1356
	return (err);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9873
diff changeset
  1357
}
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9873
diff changeset
  1358
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 9873
diff changeset
  1359
int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1360
zap_get_stats(objset_t *os, uint64_t zapobj, zap_stats_t *zs)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1361
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1362
	int err;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1363
	zap_t *zap;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1364
5384
8eba72d775e9 6623831 assertion failed in dmu_tx_willuse_space() from mzap_upgrade()
ahrens
parents: 5331
diff changeset
  1365
	err = zap_lockdir(os, zapobj, NULL, RW_READER, TRUE, FALSE, &zap);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1366
	if (err)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1367
		return (err);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1368
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1369
	bzero(zs, sizeof (zap_stats_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1370
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1371
	if (zap->zap_ismicro) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1372
		zs->zs_blocksize = zap->zap_dbuf->db_size;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1373
		zs->zs_num_entries = zap->zap_m.zap_num_entries;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1374
		zs->zs_num_blocks = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1375
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1376
		fzap_get_stats(zap, zs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1377
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1378
	zap_unlockdir(zap);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1379
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1380
}
9653
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1381
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1382
int
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1383
zap_count_write(objset_t *os, uint64_t zapobj, const char *name, int add,
9873
8ddc892eca6e 6847229 assertion failed: refcount_count(&tx->tx_space_written) + delta <= tx->tx_space_towrite in dmu_tx.c
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9653
diff changeset
  1384
    uint64_t *towrite, uint64_t *tooverwrite)
9653
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1385
{
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1386
	zap_t *zap;
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1387
	int err = 0;
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1388
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1389
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1390
	/*
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1391
	 * Since, we don't have a name, we cannot figure out which blocks will
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1392
	 * be affected in this operation. So, account for the worst case :
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1393
	 * - 3 blocks overwritten: target leaf, ptrtbl block, header block
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1394
	 * - 4 new blocks written if adding:
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1395
	 * 	- 2 blocks for possibly split leaves,
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1396
	 * 	- 2 grown ptrtbl blocks
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1397
	 *
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1398
	 * This also accomodates the case where an add operation to a fairly
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1399
	 * large microzap results in a promotion to fatzap.
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1400
	 */
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1401
	if (name == NULL) {
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1402
		*towrite += (3 + (add ? 4 : 0)) * SPA_MAXBLOCKSIZE;
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1403
		return (err);
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1404
	}
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1405
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1406
	/*
13524
f0e12b33f77c 1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents: 13512
diff changeset
  1407
	 * We lock the zap with adding == FALSE. Because, if we pass
9653
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1408
	 * the actual value of add, it could trigger a mzap_upgrade().
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1409
	 * At present we are just evaluating the possibility of this operation
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1410
	 * and hence we donot want to trigger an upgrade.
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1411
	 */
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1412
	err = zap_lockdir(os, zapobj, NULL, RW_READER, TRUE, FALSE, &zap);
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1413
	if (err)
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1414
		return (err);
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1415
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1416
	if (!zap->zap_ismicro) {
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1417
		zap_name_t *zn = zap_name_alloc(zap, name, MT_EXACT);
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1418
		if (zn) {
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1419
			err = fzap_count_write(zn, add, towrite,
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1420
			    tooverwrite);
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1421
			zap_name_free(zn);
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1422
		} else {
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1423
			/*
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1424
			 * We treat this case as similar to (name == NULL)
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1425
			 */
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1426
			*towrite += (3 + (add ? 4 : 0)) * SPA_MAXBLOCKSIZE;
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1427
		}
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1428
	} else {
9873
8ddc892eca6e 6847229 assertion failed: refcount_count(&tx->tx_space_written) + delta <= tx->tx_space_towrite in dmu_tx.c
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9653
diff changeset
  1429
		/*
8ddc892eca6e 6847229 assertion failed: refcount_count(&tx->tx_space_written) + delta <= tx->tx_space_towrite in dmu_tx.c
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9653
diff changeset
  1430
		 * We are here if (name != NULL) and this is a micro-zap.
8ddc892eca6e 6847229 assertion failed: refcount_count(&tx->tx_space_written) + delta <= tx->tx_space_towrite in dmu_tx.c
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9653
diff changeset
  1431
		 * We account for the header block depending on whether it
8ddc892eca6e 6847229 assertion failed: refcount_count(&tx->tx_space_written) + delta <= tx->tx_space_towrite in dmu_tx.c
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9653
diff changeset
  1432
		 * is freeable.
8ddc892eca6e 6847229 assertion failed: refcount_count(&tx->tx_space_written) + delta <= tx->tx_space_towrite in dmu_tx.c
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9653
diff changeset
  1433
		 *
8ddc892eca6e 6847229 assertion failed: refcount_count(&tx->tx_space_written) + delta <= tx->tx_space_towrite in dmu_tx.c
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9653
diff changeset
  1434
		 * Incase of an add-operation it is hard to find out
8ddc892eca6e 6847229 assertion failed: refcount_count(&tx->tx_space_written) + delta <= tx->tx_space_towrite in dmu_tx.c
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9653
diff changeset
  1435
		 * if this add will promote this microzap to fatzap.
8ddc892eca6e 6847229 assertion failed: refcount_count(&tx->tx_space_written) + delta <= tx->tx_space_towrite in dmu_tx.c
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9653
diff changeset
  1436
		 * Hence, we consider the worst case and account for the
8ddc892eca6e 6847229 assertion failed: refcount_count(&tx->tx_space_written) + delta <= tx->tx_space_towrite in dmu_tx.c
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9653
diff changeset
  1437
		 * blocks assuming this microzap would be promoted to a
8ddc892eca6e 6847229 assertion failed: refcount_count(&tx->tx_space_written) + delta <= tx->tx_space_towrite in dmu_tx.c
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9653
diff changeset
  1438
		 * fatzap.
8ddc892eca6e 6847229 assertion failed: refcount_count(&tx->tx_space_written) + delta <= tx->tx_space_towrite in dmu_tx.c
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9653
diff changeset
  1439
		 *
8ddc892eca6e 6847229 assertion failed: refcount_count(&tx->tx_space_written) + delta <= tx->tx_space_towrite in dmu_tx.c
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9653
diff changeset
  1440
		 * 1 block overwritten  : header block
8ddc892eca6e 6847229 assertion failed: refcount_count(&tx->tx_space_written) + delta <= tx->tx_space_towrite in dmu_tx.c
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9653
diff changeset
  1441
		 * 4 new blocks written : 2 new split leaf, 2 grown
8ddc892eca6e 6847229 assertion failed: refcount_count(&tx->tx_space_written) + delta <= tx->tx_space_towrite in dmu_tx.c
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9653
diff changeset
  1442
		 *			ptrtbl blocks
8ddc892eca6e 6847229 assertion failed: refcount_count(&tx->tx_space_written) + delta <= tx->tx_space_towrite in dmu_tx.c
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9653
diff changeset
  1443
		 */
8ddc892eca6e 6847229 assertion failed: refcount_count(&tx->tx_space_written) + delta <= tx->tx_space_towrite in dmu_tx.c
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9653
diff changeset
  1444
		if (dmu_buf_freeable(zap->zap_dbuf))
8ddc892eca6e 6847229 assertion failed: refcount_count(&tx->tx_space_written) + delta <= tx->tx_space_towrite in dmu_tx.c
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9653
diff changeset
  1445
			*tooverwrite += SPA_MAXBLOCKSIZE;
8ddc892eca6e 6847229 assertion failed: refcount_count(&tx->tx_space_written) + delta <= tx->tx_space_towrite in dmu_tx.c
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9653
diff changeset
  1446
		else
8ddc892eca6e 6847229 assertion failed: refcount_count(&tx->tx_space_written) + delta <= tx->tx_space_towrite in dmu_tx.c
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9653
diff changeset
  1447
			*towrite += SPA_MAXBLOCKSIZE;
8ddc892eca6e 6847229 assertion failed: refcount_count(&tx->tx_space_written) + delta <= tx->tx_space_towrite in dmu_tx.c
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9653
diff changeset
  1448
8ddc892eca6e 6847229 assertion failed: refcount_count(&tx->tx_space_written) + delta <= tx->tx_space_towrite in dmu_tx.c
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9653
diff changeset
  1449
		if (add) {
8ddc892eca6e 6847229 assertion failed: refcount_count(&tx->tx_space_written) + delta <= tx->tx_space_towrite in dmu_tx.c
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9653
diff changeset
  1450
			*towrite += 4 * SPA_MAXBLOCKSIZE;
9653
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1451
		}
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1452
	}
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1453
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1454
	zap_unlockdir(zap);
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1455
	return (err);
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8748
diff changeset
  1456
}