usr/src/uts/common/fs/zfs/zap.c
author Christopher Siden <chris.siden@delphix.com>
Mon, 21 May 2012 12:11:39 -0700
changeset 13700 2889e2596bd6
parent 12450 c77e20e4e046
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: 12450
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
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    26
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    27
 * This file contains the top half of the zfs directory structure
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    28
 * implementation. The bottom half is in zap_leaf.c.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    29
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    30
 * The zdir is an extendable hash data structure. There is a table of
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    31
 * pointers to buckets (zap_t->zd_data->zd_leafs). The buckets are
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    32
 * each a constant size and hold a variable number of directory entries.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    33
 * The buckets (aka "leaf nodes") are implemented in zap_leaf.c.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    34
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    35
 * The pointer table holds a power of 2 number of pointers.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    36
 * (1<<zap_t->zd_data->zd_phys->zd_prefix_len).  The bucket pointed to
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    37
 * by the pointer at index i in the table holds entries whose hash value
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    38
 * has a zd_prefix_len - bit prefix
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    39
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    40
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    41
#include <sys/spa.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    42
#include <sys/dmu.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    43
#include <sys/zfs_context.h>
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5497
diff changeset
    44
#include <sys/zfs_znode.h>
9643
ffd8e7765f02 6736004 zvols need an additional property for comstar support
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7046
diff changeset
    45
#include <sys/fs/zfs.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    46
#include <sys/zap.h>
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
    47
#include <sys/refcount.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    48
#include <sys/zap_impl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    49
#include <sys/zap_leaf.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    50
1491
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
    51
int fzap_default_block_shift = 14; /* 16k blocksize */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    52
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    53
static void zap_leaf_pageout(dmu_buf_t *db, void *vl);
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
    54
static uint64_t zap_allocate_blocks(zap_t *zap, int nblocks);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    55
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    56
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    57
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    58
fzap_byteswap(void *vbuf, size_t size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    59
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    60
	uint64_t block_type;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    61
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    62
	block_type = *(uint64_t *)vbuf;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    63
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2641
diff changeset
    64
	if (block_type == ZBT_LEAF || block_type == BSWAP_64(ZBT_LEAF))
1491
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
    65
		zap_leaf_byteswap(vbuf, size);
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2641
diff changeset
    66
	else {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    67
		/* it's a ptrtbl block */
1491
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
    68
		byteswap_uint64_array(vbuf, size);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    69
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    70
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    71
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    72
void
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
    73
fzap_upgrade(zap_t *zap, dmu_tx_t *tx, zap_flags_t flags)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    74
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    75
	dmu_buf_t *db;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    76
	zap_leaf_t *l;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    77
	int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    78
	zap_phys_t *zp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    79
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    80
	ASSERT(RW_WRITE_HELD(&zap->zap_rwlock));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    81
	zap->zap_ismicro = FALSE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    82
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    83
	(void) dmu_buf_update_user(zap->zap_dbuf, zap, zap,
2641
967ea438b194 6462174 zap_update() likes to return 0
ahrens
parents: 1632
diff changeset
    84
	    &zap->zap_f.zap_phys, zap_evict);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    85
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    86
	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
    87
	zap->zap_f.zap_block_shift = highbit(zap->zap_dbuf->db_size) - 1;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    88
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    89
	zp = zap->zap_f.zap_phys;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    90
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    91
	 * explicitly zero it since it might be coming from an
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    92
	 * initialized microzap
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    93
	 */
1491
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
    94
	bzero(zap->zap_dbuf->db_data, zap->zap_dbuf->db_size);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    95
	zp->zap_block_type = ZBT_HEADER;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    96
	zp->zap_magic = ZAP_MAGIC;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    97
1491
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
    98
	zp->zap_ptrtbl.zt_shift = ZAP_EMBEDDED_PTRTBL_SHIFT(zap);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    99
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   100
	zp->zap_freeblk = 2;		/* block 1 will be the first leaf */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   101
	zp->zap_num_leafs = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   102
	zp->zap_num_entries = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   103
	zp->zap_salt = zap->zap_salt;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4577
diff changeset
   104
	zp->zap_normflags = zap->zap_normflags;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   105
	zp->zap_flags = flags;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   106
1491
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   107
	/* block 1 will be the first leaf */
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   108
	for (i = 0; i < (1<<zp->zap_ptrtbl.zt_shift); i++)
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   109
		ZAP_EMBEDDED_PTRTBL_ENT(zap, i) = 1;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   110
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   111
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   112
	 * set up block 1 - the first leaf
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   113
	 */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   114
	VERIFY(0 == dmu_buf_hold(zap->zap_objset, zap->zap_object,
12285
d736d62dcca2 6944833 Avoid prefetching dbufs in dmu_sync() path
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11165
diff changeset
   115
	    1<<FZAP_BLOCK_SHIFT(zap), FTAG, &db, DMU_READ_NO_PREFETCH));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   116
	dmu_buf_will_dirty(db, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   117
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   118
	l = kmem_zalloc(sizeof (zap_leaf_t), KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   119
	l->l_dbuf = db;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   120
	l->l_phys = db->db_data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   121
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5497
diff changeset
   122
	zap_leaf_init(l, zp->zap_normflags != 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   123
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   124
	kmem_free(l, sizeof (zap_leaf_t));
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   125
	dmu_buf_rele(db, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   126
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   127
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   128
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   129
zap_tryupgradedir(zap_t *zap, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   130
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   131
	if (RW_WRITE_HELD(&zap->zap_rwlock))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   132
		return (1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   133
	if (rw_tryupgrade(&zap->zap_rwlock)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   134
		dmu_buf_will_dirty(zap->zap_dbuf, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   135
		return (1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   136
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   137
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   138
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   139
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   140
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   141
 * Generic routines for dealing with the pointer & cookie tables.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   142
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   143
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   144
static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   145
zap_table_grow(zap_t *zap, zap_table_phys_t *tbl,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   146
    void (*transfer_func)(const uint64_t *src, uint64_t *dst, int n),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   147
    dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   148
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   149
	uint64_t b, newblk;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   150
	dmu_buf_t *db_old, *db_new;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   151
	int err;
1491
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   152
	int bs = FZAP_BLOCK_SHIFT(zap);
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   153
	int hepb = 1<<(bs-4);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   154
	/* hepb = half the number of entries in a block */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   155
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   156
	ASSERT(RW_WRITE_HELD(&zap->zap_rwlock));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   157
	ASSERT(tbl->zt_blk != 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   158
	ASSERT(tbl->zt_numblks > 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   159
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   160
	if (tbl->zt_nextblk != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   161
		newblk = tbl->zt_nextblk;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   162
	} else {
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   163
		newblk = zap_allocate_blocks(zap, tbl->zt_numblks * 2);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   164
		tbl->zt_nextblk = newblk;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   165
		ASSERT3U(tbl->zt_blks_copied, ==, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   166
		dmu_prefetch(zap->zap_objset, zap->zap_object,
1491
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   167
		    tbl->zt_blk << bs, tbl->zt_numblks << bs);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   168
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   169
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   170
	/*
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   171
	 * Copy the ptrtbl from the old to new location.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   172
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   173
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   174
	b = tbl->zt_blks_copied;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   175
	err = dmu_buf_hold(zap->zap_objset, zap->zap_object,
12285
d736d62dcca2 6944833 Avoid prefetching dbufs in dmu_sync() path
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11165
diff changeset
   176
	    (tbl->zt_blk + b) << bs, FTAG, &db_old, DMU_READ_NO_PREFETCH);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   177
	if (err)
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   178
		return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   179
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   180
	/* first half of entries in old[b] go to new[2*b+0] */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   181
	VERIFY(0 == dmu_buf_hold(zap->zap_objset, zap->zap_object,
12285
d736d62dcca2 6944833 Avoid prefetching dbufs in dmu_sync() path
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11165
diff changeset
   182
	    (newblk + 2*b+0) << bs, FTAG, &db_new, DMU_READ_NO_PREFETCH));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   183
	dmu_buf_will_dirty(db_new, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   184
	transfer_func(db_old->db_data, db_new->db_data, hepb);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   185
	dmu_buf_rele(db_new, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   186
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   187
	/* second half of entries in old[b] go to new[2*b+1] */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   188
	VERIFY(0 == dmu_buf_hold(zap->zap_objset, zap->zap_object,
12285
d736d62dcca2 6944833 Avoid prefetching dbufs in dmu_sync() path
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11165
diff changeset
   189
	    (newblk + 2*b+1) << bs, FTAG, &db_new, DMU_READ_NO_PREFETCH));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   190
	dmu_buf_will_dirty(db_new, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   191
	transfer_func((uint64_t *)db_old->db_data + hepb,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   192
	    db_new->db_data, hepb);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   193
	dmu_buf_rele(db_new, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   194
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   195
	dmu_buf_rele(db_old, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   196
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   197
	tbl->zt_blks_copied++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   198
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   199
	dprintf("copied block %llu of %llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   200
	    tbl->zt_blks_copied, tbl->zt_numblks);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   201
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   202
	if (tbl->zt_blks_copied == tbl->zt_numblks) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   203
		(void) dmu_free_range(zap->zap_objset, zap->zap_object,
1491
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   204
		    tbl->zt_blk << bs, tbl->zt_numblks << bs, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   205
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   206
		tbl->zt_blk = newblk;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   207
		tbl->zt_numblks *= 2;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   208
		tbl->zt_shift++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   209
		tbl->zt_nextblk = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   210
		tbl->zt_blks_copied = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   211
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   212
		dprintf("finished; numblocks now %llu (%lluk entries)\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   213
		    tbl->zt_numblks, 1<<(tbl->zt_shift-10));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   214
	}
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   215
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   216
	return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   217
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   218
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   219
static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   220
zap_table_store(zap_t *zap, zap_table_phys_t *tbl, uint64_t idx, uint64_t val,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   221
    dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   222
{
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   223
	int err;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   224
	uint64_t blk, off;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   225
	int bs = FZAP_BLOCK_SHIFT(zap);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   226
	dmu_buf_t *db;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   227
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   228
	ASSERT(RW_LOCK_HELD(&zap->zap_rwlock));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   229
	ASSERT(tbl->zt_blk != 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   230
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   231
	dprintf("storing %llx at index %llx\n", val, idx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   232
1491
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   233
	blk = idx >> (bs-3);
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   234
	off = idx & ((1<<(bs-3))-1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   235
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   236
	err = dmu_buf_hold(zap->zap_objset, zap->zap_object,
12285
d736d62dcca2 6944833 Avoid prefetching dbufs in dmu_sync() path
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11165
diff changeset
   237
	    (tbl->zt_blk + blk) << bs, FTAG, &db, DMU_READ_NO_PREFETCH);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   238
	if (err)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   239
		return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   240
	dmu_buf_will_dirty(db, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   241
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   242
	if (tbl->zt_nextblk != 0) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   243
		uint64_t idx2 = idx * 2;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   244
		uint64_t blk2 = idx2 >> (bs-3);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   245
		uint64_t off2 = idx2 & ((1<<(bs-3))-1);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   246
		dmu_buf_t *db2;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   247
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   248
		err = dmu_buf_hold(zap->zap_objset, zap->zap_object,
12285
d736d62dcca2 6944833 Avoid prefetching dbufs in dmu_sync() path
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11165
diff changeset
   249
		    (tbl->zt_nextblk + blk2) << bs, FTAG, &db2,
d736d62dcca2 6944833 Avoid prefetching dbufs in dmu_sync() path
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11165
diff changeset
   250
		    DMU_READ_NO_PREFETCH);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   251
		if (err) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   252
			dmu_buf_rele(db, FTAG);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   253
			return (err);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   254
		}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   255
		dmu_buf_will_dirty(db2, tx);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   256
		((uint64_t *)db2->db_data)[off2] = val;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   257
		((uint64_t *)db2->db_data)[off2+1] = val;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   258
		dmu_buf_rele(db2, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   259
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   260
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   261
	((uint64_t *)db->db_data)[off] = val;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   262
	dmu_buf_rele(db, FTAG);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   263
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   264
	return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   265
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   266
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   267
static int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   268
zap_table_load(zap_t *zap, zap_table_phys_t *tbl, uint64_t idx, uint64_t *valp)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   269
{
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   270
	uint64_t blk, off;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   271
	int err;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   272
	dmu_buf_t *db;
1491
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   273
	int bs = FZAP_BLOCK_SHIFT(zap);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   274
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   275
	ASSERT(RW_LOCK_HELD(&zap->zap_rwlock));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   276
1491
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   277
	blk = idx >> (bs-3);
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   278
	off = idx & ((1<<(bs-3))-1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   279
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   280
	err = dmu_buf_hold(zap->zap_objset, zap->zap_object,
12285
d736d62dcca2 6944833 Avoid prefetching dbufs in dmu_sync() path
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11165
diff changeset
   281
	    (tbl->zt_blk + blk) << bs, FTAG, &db, DMU_READ_NO_PREFETCH);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   282
	if (err)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   283
		return (err);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   284
	*valp = ((uint64_t *)db->db_data)[off];
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   285
	dmu_buf_rele(db, FTAG);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   286
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   287
	if (tbl->zt_nextblk != 0) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   288
		/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   289
		 * read the nextblk for the sake of i/o error checking,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   290
		 * so that zap_table_load() will catch errors for
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   291
		 * zap_table_store.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   292
		 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   293
		blk = (idx*2) >> (bs-3);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   294
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   295
		err = dmu_buf_hold(zap->zap_objset, zap->zap_object,
12285
d736d62dcca2 6944833 Avoid prefetching dbufs in dmu_sync() path
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11165
diff changeset
   296
		    (tbl->zt_nextblk + blk) << bs, FTAG, &db,
d736d62dcca2 6944833 Avoid prefetching dbufs in dmu_sync() path
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11165
diff changeset
   297
		    DMU_READ_NO_PREFETCH);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   298
		dmu_buf_rele(db, FTAG);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   299
	}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   300
	return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   301
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   302
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   303
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   304
 * Routines for growing the ptrtbl.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   305
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   306
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   307
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   308
zap_ptrtbl_transfer(const uint64_t *src, uint64_t *dst, int n)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   309
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   310
	int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   311
	for (i = 0; i < n; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   312
		uint64_t lb = src[i];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   313
		dst[2*i+0] = lb;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   314
		dst[2*i+1] = lb;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   315
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   316
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   317
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   318
static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   319
zap_grow_ptrtbl(zap_t *zap, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   320
{
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   321
	/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   322
	 * The pointer table should never use more hash bits than we
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   323
	 * have (otherwise we'd be using useless zero bits to index it).
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   324
	 * If we are within 2 bits of running out, stop growing, since
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   325
	 * this is already an aberrant condition.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   326
	 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   327
	if (zap->zap_f.zap_phys->zap_ptrtbl.zt_shift >= zap_hashbits(zap) - 2)
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   328
		return (ENOSPC);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   329
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   330
	if (zap->zap_f.zap_phys->zap_ptrtbl.zt_numblks == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   331
		/*
1491
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   332
		 * We are outgrowing the "embedded" ptrtbl (the one
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   333
		 * stored in the header block).  Give it its own entire
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   334
		 * block, which will double the size of the ptrtbl.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   335
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   336
		uint64_t newblk;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   337
		dmu_buf_t *db_new;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   338
		int err;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   339
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   340
		ASSERT3U(zap->zap_f.zap_phys->zap_ptrtbl.zt_shift, ==,
1491
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   341
		    ZAP_EMBEDDED_PTRTBL_SHIFT(zap));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   342
		ASSERT3U(zap->zap_f.zap_phys->zap_ptrtbl.zt_blk, ==, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   343
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   344
		newblk = zap_allocate_blocks(zap, 1);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   345
		err = dmu_buf_hold(zap->zap_objset, zap->zap_object,
12285
d736d62dcca2 6944833 Avoid prefetching dbufs in dmu_sync() path
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11165
diff changeset
   346
		    newblk << FZAP_BLOCK_SHIFT(zap), FTAG, &db_new,
d736d62dcca2 6944833 Avoid prefetching dbufs in dmu_sync() path
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11165
diff changeset
   347
		    DMU_READ_NO_PREFETCH);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   348
		if (err)
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   349
			return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   350
		dmu_buf_will_dirty(db_new, tx);
1491
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   351
		zap_ptrtbl_transfer(&ZAP_EMBEDDED_PTRTBL_ENT(zap, 0),
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   352
		    db_new->db_data, 1 << ZAP_EMBEDDED_PTRTBL_SHIFT(zap));
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   353
		dmu_buf_rele(db_new, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   354
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   355
		zap->zap_f.zap_phys->zap_ptrtbl.zt_blk = newblk;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   356
		zap->zap_f.zap_phys->zap_ptrtbl.zt_numblks = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   357
		zap->zap_f.zap_phys->zap_ptrtbl.zt_shift++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   358
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   359
		ASSERT3U(1ULL << zap->zap_f.zap_phys->zap_ptrtbl.zt_shift, ==,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   360
		    zap->zap_f.zap_phys->zap_ptrtbl.zt_numblks <<
1491
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   361
		    (FZAP_BLOCK_SHIFT(zap)-3));
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   362
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   363
		return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   364
	} else {
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   365
		return (zap_table_grow(zap, &zap->zap_f.zap_phys->zap_ptrtbl,
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   366
		    zap_ptrtbl_transfer, tx));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   367
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   368
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   369
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   370
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   371
zap_increment_num_entries(zap_t *zap, int delta, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   372
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   373
	dmu_buf_will_dirty(zap->zap_dbuf, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   374
	mutex_enter(&zap->zap_f.zap_num_entries_mtx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   375
	ASSERT(delta > 0 || zap->zap_f.zap_phys->zap_num_entries >= -delta);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   376
	zap->zap_f.zap_phys->zap_num_entries += delta;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   377
	mutex_exit(&zap->zap_f.zap_num_entries_mtx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   378
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   379
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   380
static uint64_t
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   381
zap_allocate_blocks(zap_t *zap, int nblocks)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   382
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   383
	uint64_t newblk;
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   384
	ASSERT(RW_WRITE_HELD(&zap->zap_rwlock));
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   385
	newblk = zap->zap_f.zap_phys->zap_freeblk;
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   386
	zap->zap_f.zap_phys->zap_freeblk += nblocks;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   387
	return (newblk);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   388
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   389
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   390
static zap_leaf_t *
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   391
zap_create_leaf(zap_t *zap, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   392
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   393
	void *winner;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   394
	zap_leaf_t *l = kmem_alloc(sizeof (zap_leaf_t), KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   395
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   396
	ASSERT(RW_WRITE_HELD(&zap->zap_rwlock));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   397
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   398
	rw_init(&l->l_rwlock, 0, 0, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   399
	rw_enter(&l->l_rwlock, RW_WRITER);
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   400
	l->l_blkid = zap_allocate_blocks(zap, 1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   401
	l->l_dbuf = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   402
	l->l_phys = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   403
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   404
	VERIFY(0 == dmu_buf_hold(zap->zap_objset, zap->zap_object,
12285
d736d62dcca2 6944833 Avoid prefetching dbufs in dmu_sync() path
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11165
diff changeset
   405
	    l->l_blkid << FZAP_BLOCK_SHIFT(zap), NULL, &l->l_dbuf,
d736d62dcca2 6944833 Avoid prefetching dbufs in dmu_sync() path
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11165
diff changeset
   406
	    DMU_READ_NO_PREFETCH));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   407
	winner = dmu_buf_set_user(l->l_dbuf, l, &l->l_phys, zap_leaf_pageout);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   408
	ASSERT(winner == NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   409
	dmu_buf_will_dirty(l->l_dbuf, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   410
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5497
diff changeset
   411
	zap_leaf_init(l, zap->zap_normflags != 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   412
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   413
	zap->zap_f.zap_phys->zap_num_leafs++;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   414
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   415
	return (l);
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
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   419
fzap_count(zap_t *zap, uint64_t *count)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   420
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   421
	ASSERT(!zap->zap_ismicro);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   422
	mutex_enter(&zap->zap_f.zap_num_entries_mtx); /* unnecessary */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   423
	*count = zap->zap_f.zap_phys->zap_num_entries;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   424
	mutex_exit(&zap->zap_f.zap_num_entries_mtx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   425
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   426
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   427
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   428
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   429
 * Routines for obtaining zap_leaf_t's
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   430
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   431
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
   432
void
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   433
zap_put_leaf(zap_leaf_t *l)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   434
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   435
	rw_exit(&l->l_rwlock);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   436
	dmu_buf_rele(l->l_dbuf, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   437
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   438
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   439
_NOTE(ARGSUSED(0))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   440
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   441
zap_leaf_pageout(dmu_buf_t *db, void *vl)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   442
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   443
	zap_leaf_t *l = vl;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   444
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   445
	rw_destroy(&l->l_rwlock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   446
	kmem_free(l, sizeof (zap_leaf_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   447
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   448
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   449
static zap_leaf_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   450
zap_open_leaf(uint64_t blkid, dmu_buf_t *db)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   451
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   452
	zap_leaf_t *l, *winner;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   453
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   454
	ASSERT(blkid != 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   455
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   456
	l = kmem_alloc(sizeof (zap_leaf_t), KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   457
	rw_init(&l->l_rwlock, 0, 0, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   458
	rw_enter(&l->l_rwlock, RW_WRITER);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   459
	l->l_blkid = blkid;
1491
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   460
	l->l_bs = highbit(db->db_size)-1;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   461
	l->l_dbuf = db;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   462
	l->l_phys = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   463
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   464
	winner = dmu_buf_set_user(db, l, &l->l_phys, zap_leaf_pageout);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   465
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   466
	rw_exit(&l->l_rwlock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   467
	if (winner != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   468
		/* someone else set it first */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   469
		zap_leaf_pageout(NULL, l);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   470
		l = winner;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   471
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   472
1491
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   473
	/*
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   474
	 * lhr_pad was previously used for the next leaf in the leaf
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   475
	 * chain.  There should be no chained leafs (as we have removed
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   476
	 * support for them).
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   477
	 */
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   478
	ASSERT3U(l->l_phys->l_hdr.lh_pad1, ==, 0);
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   479
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   480
	/*
1491
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   481
	 * There should be more hash entries than there can be
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   482
	 * chunks to put in the hash table
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   483
	 */
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   484
	ASSERT3U(ZAP_LEAF_HASH_NUMENTRIES(l), >, ZAP_LEAF_NUMCHUNKS(l) / 3);
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   485
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   486
	/* The chunks should begin at the end of the hash table */
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   487
	ASSERT3P(&ZAP_LEAF_CHUNK(l, 0), ==,
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   488
	    &l->l_phys->l_hash[ZAP_LEAF_HASH_NUMENTRIES(l)]);
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   489
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   490
	/* The chunks should end at the end of the block */
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   491
	ASSERT3U((uintptr_t)&ZAP_LEAF_CHUNK(l, ZAP_LEAF_NUMCHUNKS(l)) -
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   492
	    (uintptr_t)l->l_phys, ==, l->l_dbuf->db_size);
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   493
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   494
	return (l);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   495
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   496
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   497
static int
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   498
zap_get_leaf_byblk(zap_t *zap, uint64_t blkid, dmu_tx_t *tx, krw_t lt,
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   499
    zap_leaf_t **lp)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   500
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   501
	dmu_buf_t *db;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   502
	zap_leaf_t *l;
1491
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   503
	int bs = FZAP_BLOCK_SHIFT(zap);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   504
	int err;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   505
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   506
	ASSERT(RW_LOCK_HELD(&zap->zap_rwlock));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   507
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   508
	err = dmu_buf_hold(zap->zap_objset, zap->zap_object,
12285
d736d62dcca2 6944833 Avoid prefetching dbufs in dmu_sync() path
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11165
diff changeset
   509
	    blkid << bs, NULL, &db, DMU_READ_NO_PREFETCH);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   510
	if (err)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   511
		return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   512
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   513
	ASSERT3U(db->db_object, ==, zap->zap_object);
1491
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   514
	ASSERT3U(db->db_offset, ==, blkid << bs);
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   515
	ASSERT3U(db->db_size, ==, 1 << bs);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   516
	ASSERT(blkid != 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   517
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   518
	l = dmu_buf_get_user(db);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   519
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   520
	if (l == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   521
		l = zap_open_leaf(blkid, db);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   522
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   523
	rw_enter(&l->l_rwlock, lt);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   524
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   525
	 * Must lock before dirtying, otherwise l->l_phys could change,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   526
	 * causing ASSERT below to fail.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   527
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   528
	if (lt == RW_WRITER)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   529
		dmu_buf_will_dirty(db, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   530
	ASSERT3U(l->l_blkid, ==, blkid);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   531
	ASSERT3P(l->l_dbuf, ==, db);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   532
	ASSERT3P(l->l_phys, ==, l->l_dbuf->db_data);
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   533
	ASSERT3U(l->l_phys->l_hdr.lh_block_type, ==, ZBT_LEAF);
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   534
	ASSERT3U(l->l_phys->l_hdr.lh_magic, ==, ZAP_LEAF_MAGIC);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   535
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   536
	*lp = l;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   537
	return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   538
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   539
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   540
static int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   541
zap_idx_to_blk(zap_t *zap, uint64_t idx, uint64_t *valp)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   542
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   543
	ASSERT(RW_LOCK_HELD(&zap->zap_rwlock));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   544
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   545
	if (zap->zap_f.zap_phys->zap_ptrtbl.zt_numblks == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   546
		ASSERT3U(idx, <,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   547
		    (1ULL << zap->zap_f.zap_phys->zap_ptrtbl.zt_shift));
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   548
		*valp = ZAP_EMBEDDED_PTRTBL_ENT(zap, idx);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   549
		return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   550
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   551
		return (zap_table_load(zap, &zap->zap_f.zap_phys->zap_ptrtbl,
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   552
		    idx, valp));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   553
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   554
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   555
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   556
static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   557
zap_set_idx_to_blk(zap_t *zap, uint64_t idx, uint64_t blk, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   558
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   559
	ASSERT(tx != NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   560
	ASSERT(RW_WRITE_HELD(&zap->zap_rwlock));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   561
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   562
	if (zap->zap_f.zap_phys->zap_ptrtbl.zt_blk == 0) {
1491
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
   563
		ZAP_EMBEDDED_PTRTBL_ENT(zap, idx) = blk;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   564
		return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   565
	} else {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   566
		return (zap_table_store(zap, &zap->zap_f.zap_phys->zap_ptrtbl,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   567
		    idx, blk, tx));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   568
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   569
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   570
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   571
static int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   572
zap_deref_leaf(zap_t *zap, uint64_t h, dmu_tx_t *tx, krw_t lt, zap_leaf_t **lp)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   573
{
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   574
	uint64_t idx, blk;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   575
	int err;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   576
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   577
	ASSERT(zap->zap_dbuf == NULL ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   578
	    zap->zap_f.zap_phys == zap->zap_dbuf->db_data);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   579
	ASSERT3U(zap->zap_f.zap_phys->zap_magic, ==, ZAP_MAGIC);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   580
	idx = ZAP_HASH_IDX(h, zap->zap_f.zap_phys->zap_ptrtbl.zt_shift);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   581
	err = zap_idx_to_blk(zap, idx, &blk);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   582
	if (err != 0)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   583
		return (err);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   584
	err = zap_get_leaf_byblk(zap, blk, tx, lt, lp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   585
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   586
	ASSERT(err || ZAP_HASH_IDX(h, (*lp)->l_phys->l_hdr.lh_prefix_len) ==
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   587
	    (*lp)->l_phys->l_hdr.lh_prefix);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   588
	return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   589
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   590
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   591
static int
5497
913e555b2de5 6626801 deadbeef panic in fzap_update()
bonwick
parents: 5384
diff changeset
   592
zap_expand_leaf(zap_name_t *zn, zap_leaf_t *l, dmu_tx_t *tx, zap_leaf_t **lp)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   593
{
5497
913e555b2de5 6626801 deadbeef panic in fzap_update()
bonwick
parents: 5384
diff changeset
   594
	zap_t *zap = zn->zn_zap;
913e555b2de5 6626801 deadbeef panic in fzap_update()
bonwick
parents: 5384
diff changeset
   595
	uint64_t hash = zn->zn_hash;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   596
	zap_leaf_t *nl;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   597
	int prefix_diff, i, err;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   598
	uint64_t sibling;
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   599
	int old_prefix_len = l->l_phys->l_hdr.lh_prefix_len;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   600
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   601
	ASSERT3U(old_prefix_len, <=, zap->zap_f.zap_phys->zap_ptrtbl.zt_shift);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   602
	ASSERT(RW_LOCK_HELD(&zap->zap_rwlock));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   603
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   604
	ASSERT3U(ZAP_HASH_IDX(hash, old_prefix_len), ==,
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   605
	    l->l_phys->l_hdr.lh_prefix);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   606
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   607
	if (zap_tryupgradedir(zap, tx) == 0 ||
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   608
	    old_prefix_len == zap->zap_f.zap_phys->zap_ptrtbl.zt_shift) {
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   609
		/* We failed to upgrade, or need to grow the pointer table */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   610
		objset_t *os = zap->zap_objset;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   611
		uint64_t object = zap->zap_object;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   612
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   613
		zap_put_leaf(l);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   614
		zap_unlockdir(zap);
5384
8eba72d775e9 6623831 assertion failed in dmu_tx_willuse_space() from mzap_upgrade()
ahrens
parents: 5331
diff changeset
   615
		err = zap_lockdir(os, object, tx, RW_WRITER,
5497
913e555b2de5 6626801 deadbeef panic in fzap_update()
bonwick
parents: 5384
diff changeset
   616
		    FALSE, FALSE, &zn->zn_zap);
913e555b2de5 6626801 deadbeef panic in fzap_update()
bonwick
parents: 5384
diff changeset
   617
		zap = zn->zn_zap;
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   618
		if (err)
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   619
			return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   620
		ASSERT(!zap->zap_ismicro);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   621
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   622
		while (old_prefix_len ==
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   623
		    zap->zap_f.zap_phys->zap_ptrtbl.zt_shift) {
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   624
			err = zap_grow_ptrtbl(zap, tx);
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   625
			if (err)
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   626
				return (err);
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   627
		}
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   628
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   629
		err = zap_deref_leaf(zap, hash, tx, RW_WRITER, &l);
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   630
		if (err)
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   631
			return (err);
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   632
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   633
		if (l->l_phys->l_hdr.lh_prefix_len != old_prefix_len) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   634
			/* it split while our locks were down */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   635
			*lp = l;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   636
			return (0);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   637
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   638
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   639
	ASSERT(RW_WRITE_HELD(&zap->zap_rwlock));
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   640
	ASSERT3U(old_prefix_len, <, zap->zap_f.zap_phys->zap_ptrtbl.zt_shift);
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   641
	ASSERT3U(ZAP_HASH_IDX(hash, old_prefix_len), ==,
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   642
	    l->l_phys->l_hdr.lh_prefix);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   643
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   644
	prefix_diff = zap->zap_f.zap_phys->zap_ptrtbl.zt_shift -
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   645
	    (old_prefix_len + 1);
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   646
	sibling = (ZAP_HASH_IDX(hash, old_prefix_len + 1) | 1) << prefix_diff;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   647
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   648
	/* check for i/o errors before doing zap_leaf_split */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   649
	for (i = 0; i < (1ULL<<prefix_diff); i++) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   650
		uint64_t blk;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   651
		err = zap_idx_to_blk(zap, sibling+i, &blk);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   652
		if (err)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   653
			return (err);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   654
		ASSERT3U(blk, ==, l->l_blkid);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   655
	}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   656
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   657
	nl = zap_create_leaf(zap, tx);
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5497
diff changeset
   658
	zap_leaf_split(l, nl, zap->zap_normflags != 0);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   659
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   660
	/* set sibling pointers */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   661
	for (i = 0; i < (1ULL<<prefix_diff); i++) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   662
		err = zap_set_idx_to_blk(zap, sibling+i, nl->l_blkid, tx);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   663
		ASSERT3U(err, ==, 0); /* we checked for i/o errors above */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   664
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   665
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   666
	if (hash & (1ULL << (64 - l->l_phys->l_hdr.lh_prefix_len))) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   667
		/* we want the sibling */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   668
		zap_put_leaf(l);
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   669
		*lp = nl;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   670
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   671
		zap_put_leaf(nl);
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   672
		*lp = l;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   673
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   674
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   675
	return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   676
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   677
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   678
static void
5497
913e555b2de5 6626801 deadbeef panic in fzap_update()
bonwick
parents: 5384
diff changeset
   679
zap_put_leaf_maybe_grow_ptrtbl(zap_name_t *zn, zap_leaf_t *l, dmu_tx_t *tx)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   680
{
5497
913e555b2de5 6626801 deadbeef panic in fzap_update()
bonwick
parents: 5384
diff changeset
   681
	zap_t *zap = zn->zn_zap;
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   682
	int shift = zap->zap_f.zap_phys->zap_ptrtbl.zt_shift;
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   683
	int leaffull = (l->l_phys->l_hdr.lh_prefix_len == shift &&
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   684
	    l->l_phys->l_hdr.lh_nfree < ZAP_LEAF_LOW_WATER);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   685
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   686
	zap_put_leaf(l);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   687
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   688
	if (leaffull || zap->zap_f.zap_phys->zap_ptrtbl.zt_nextblk) {
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   689
		int err;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   690
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   691
		/*
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   692
		 * We are in the middle of growing the pointer table, or
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   693
		 * this leaf will soon make us grow it.
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   694
		 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   695
		if (zap_tryupgradedir(zap, tx) == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   696
			objset_t *os = zap->zap_objset;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   697
			uint64_t zapobj = zap->zap_object;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   698
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   699
			zap_unlockdir(zap);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   700
			err = zap_lockdir(os, zapobj, tx,
5497
913e555b2de5 6626801 deadbeef panic in fzap_update()
bonwick
parents: 5384
diff changeset
   701
			    RW_WRITER, FALSE, FALSE, &zn->zn_zap);
913e555b2de5 6626801 deadbeef panic in fzap_update()
bonwick
parents: 5384
diff changeset
   702
			zap = zn->zn_zap;
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   703
			if (err)
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   704
				return;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   705
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   706
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   707
		/* could have finished growing while our locks were down */
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   708
		if (zap->zap_f.zap_phys->zap_ptrtbl.zt_shift == shift)
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   709
			(void) zap_grow_ptrtbl(zap, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   710
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   711
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   712
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10922
diff changeset
   713
static int
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10922
diff changeset
   714
fzap_checkname(zap_name_t *zn)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10922
diff changeset
   715
{
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
   716
	if (zn->zn_key_orig_numints * zn->zn_key_intlen > ZAP_MAXNAMELEN)
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10922
diff changeset
   717
		return (ENAMETOOLONG);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10922
diff changeset
   718
	return (0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10922
diff changeset
   719
}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   720
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   721
static int
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10922
diff changeset
   722
fzap_checksize(uint64_t integer_size, uint64_t num_integers)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   723
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   724
	/* Only integer sizes supported by C */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   725
	switch (integer_size) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   726
	case 1:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   727
	case 2:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   728
	case 4:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   729
	case 8:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   730
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   731
	default:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   732
		return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   733
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   734
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   735
	if (integer_size * num_integers > ZAP_MAXVALUELEN)
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   736
		return (E2BIG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   737
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   738
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   739
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   740
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10922
diff changeset
   741
static int
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10922
diff changeset
   742
fzap_check(zap_name_t *zn, uint64_t integer_size, uint64_t num_integers)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10922
diff changeset
   743
{
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10922
diff changeset
   744
	int err;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10922
diff changeset
   745
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10922
diff changeset
   746
	if ((err = fzap_checkname(zn)) != 0)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10922
diff changeset
   747
		return (err);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10922
diff changeset
   748
	return (fzap_checksize(integer_size, num_integers));
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10922
diff changeset
   749
}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10922
diff changeset
   750
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   751
/*
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4577
diff changeset
   752
 * Routines for manipulating attributes.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   753
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   754
int
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4577
diff changeset
   755
fzap_lookup(zap_name_t *zn,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4577
diff changeset
   756
    uint64_t integer_size, uint64_t num_integers, void *buf,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4577
diff changeset
   757
    char *realname, int rn_len, boolean_t *ncp)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   758
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   759
	zap_leaf_t *l;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   760
	int err;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   761
	zap_entry_handle_t zeh;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   762
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10922
diff changeset
   763
	if ((err = fzap_checkname(zn)) != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   764
		return (err);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   765
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4577
diff changeset
   766
	err = zap_deref_leaf(zn->zn_zap, zn->zn_hash, NULL, RW_READER, &l);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   767
	if (err != 0)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   768
		return (err);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4577
diff changeset
   769
	err = zap_leaf_lookup(l, zn, &zeh);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4577
diff changeset
   770
	if (err == 0) {
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10922
diff changeset
   771
		if ((err = fzap_checksize(integer_size, num_integers)) != 0) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10922
diff changeset
   772
			zap_put_leaf(l);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10922
diff changeset
   773
			return (err);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10922
diff changeset
   774
		}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10922
diff changeset
   775
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   776
		err = zap_entry_read(&zeh, integer_size, num_integers, buf);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   777
		(void) zap_entry_read_name(zn->zn_zap, &zeh, rn_len, realname);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4577
diff changeset
   778
		if (ncp) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4577
diff changeset
   779
			*ncp = zap_entry_normalization_conflict(&zeh,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4577
diff changeset
   780
			    zn, NULL, zn->zn_zap);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4577
diff changeset
   781
		}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4577
diff changeset
   782
	}
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   783
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   784
	zap_put_leaf(l);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   785
	return (err);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   786
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   787
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   788
int
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4577
diff changeset
   789
fzap_add_cd(zap_name_t *zn,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   790
    uint64_t integer_size, uint64_t num_integers,
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   791
    const void *val, uint32_t cd, dmu_tx_t *tx)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   792
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   793
	zap_leaf_t *l;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   794
	int err;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   795
	zap_entry_handle_t zeh;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4577
diff changeset
   796
	zap_t *zap = zn->zn_zap;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   797
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   798
	ASSERT(RW_LOCK_HELD(&zap->zap_rwlock));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   799
	ASSERT(!zap->zap_ismicro);
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10922
diff changeset
   800
	ASSERT(fzap_check(zn, integer_size, num_integers) == 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   801
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4577
diff changeset
   802
	err = zap_deref_leaf(zap, zn->zn_hash, tx, RW_WRITER, &l);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   803
	if (err != 0)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   804
		return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   805
retry:
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4577
diff changeset
   806
	err = zap_leaf_lookup(l, zn, &zeh);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   807
	if (err == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   808
		err = EEXIST;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   809
		goto out;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   810
	}
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   811
	if (err != ENOENT)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   812
		goto out;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   813
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   814
	err = zap_entry_create(l, zn, cd,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   815
	    integer_size, num_integers, val, &zeh);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   816
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   817
	if (err == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   818
		zap_increment_num_entries(zap, 1, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   819
	} else if (err == EAGAIN) {
5497
913e555b2de5 6626801 deadbeef panic in fzap_update()
bonwick
parents: 5384
diff changeset
   820
		err = zap_expand_leaf(zn, l, tx, &l);
913e555b2de5 6626801 deadbeef panic in fzap_update()
bonwick
parents: 5384
diff changeset
   821
		zap = zn->zn_zap;	/* zap_expand_leaf() may change zap */
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   822
		if (err == 0)
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   823
			goto retry;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   824
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   825
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   826
out:
5497
913e555b2de5 6626801 deadbeef panic in fzap_update()
bonwick
parents: 5384
diff changeset
   827
	if (zap != NULL)
913e555b2de5 6626801 deadbeef panic in fzap_update()
bonwick
parents: 5384
diff changeset
   828
		zap_put_leaf_maybe_grow_ptrtbl(zn, l, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   829
	return (err);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   830
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   831
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   832
int
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4577
diff changeset
   833
fzap_add(zap_name_t *zn,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   834
    uint64_t integer_size, uint64_t num_integers,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   835
    const void *val, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   836
{
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10922
diff changeset
   837
	int err = fzap_check(zn, integer_size, num_integers);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   838
	if (err != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   839
		return (err);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   840
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4577
diff changeset
   841
	return (fzap_add_cd(zn, integer_size, num_integers,
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   842
	    val, ZAP_NEED_CD, tx));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   843
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   844
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   845
int
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4577
diff changeset
   846
fzap_update(zap_name_t *zn,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   847
    int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   848
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   849
	zap_leaf_t *l;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   850
	int err, create;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   851
	zap_entry_handle_t zeh;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4577
diff changeset
   852
	zap_t *zap = zn->zn_zap;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   853
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   854
	ASSERT(RW_LOCK_HELD(&zap->zap_rwlock));
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10922
diff changeset
   855
	err = fzap_check(zn, integer_size, num_integers);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   856
	if (err != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   857
		return (err);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   858
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4577
diff changeset
   859
	err = zap_deref_leaf(zap, zn->zn_hash, tx, RW_WRITER, &l);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   860
	if (err != 0)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   861
		return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   862
retry:
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4577
diff changeset
   863
	err = zap_leaf_lookup(l, zn, &zeh);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   864
	create = (err == ENOENT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   865
	ASSERT(err == 0 || err == ENOENT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   866
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   867
	if (create) {
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   868
		err = zap_entry_create(l, zn, ZAP_NEED_CD,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
   869
		    integer_size, num_integers, val, &zeh);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   870
		if (err == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   871
			zap_increment_num_entries(zap, 1, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   872
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   873
		err = zap_entry_update(&zeh, integer_size, num_integers, val);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   874
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   875
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   876
	if (err == EAGAIN) {
5497
913e555b2de5 6626801 deadbeef panic in fzap_update()
bonwick
parents: 5384
diff changeset
   877
		err = zap_expand_leaf(zn, l, tx, &l);
913e555b2de5 6626801 deadbeef panic in fzap_update()
bonwick
parents: 5384
diff changeset
   878
		zap = zn->zn_zap;	/* zap_expand_leaf() may change zap */
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   879
		if (err == 0)
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
   880
			goto retry;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   881
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   882
5497
913e555b2de5 6626801 deadbeef panic in fzap_update()
bonwick
parents: 5384
diff changeset
   883
	if (zap != NULL)
913e555b2de5 6626801 deadbeef panic in fzap_update()
bonwick
parents: 5384
diff changeset
   884
		zap_put_leaf_maybe_grow_ptrtbl(zn, l, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   885
	return (err);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   886
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   887
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   888
int
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4577
diff changeset
   889
fzap_length(zap_name_t *zn,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   890
    uint64_t *integer_size, uint64_t *num_integers)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   891
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   892
	zap_leaf_t *l;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   893
	int err;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   894
	zap_entry_handle_t zeh;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   895
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4577
diff changeset
   896
	err = zap_deref_leaf(zn->zn_zap, zn->zn_hash, NULL, RW_READER, &l);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   897
	if (err != 0)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   898
		return (err);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4577
diff changeset
   899
	err = zap_leaf_lookup(l, zn, &zeh);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   900
	if (err != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   901
		goto out;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   902
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   903
	if (integer_size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   904
		*integer_size = zeh.zeh_integer_size;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   905
	if (num_integers)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   906
		*num_integers = zeh.zeh_num_integers;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   907
out:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   908
	zap_put_leaf(l);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   909
	return (err);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   910
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   911
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   912
int
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4577
diff changeset
   913
fzap_remove(zap_name_t *zn, dmu_tx_t *tx)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   914
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   915
	zap_leaf_t *l;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   916
	int err;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   917
	zap_entry_handle_t zeh;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   918
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4577
diff changeset
   919
	err = zap_deref_leaf(zn->zn_zap, zn->zn_hash, tx, RW_WRITER, &l);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   920
	if (err != 0)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
   921
		return (err);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4577
diff changeset
   922
	err = zap_leaf_lookup(l, zn, &zeh);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   923
	if (err == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   924
		zap_entry_remove(&zeh);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4577
diff changeset
   925
		zap_increment_num_entries(zn->zn_zap, -1, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   926
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   927
	zap_put_leaf(l);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   928
	return (err);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   929
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   930
12450
c77e20e4e046 6938089 dedup-induced latency causes FC initiator logouts/FC port resets
George Wilson <George.Wilson@Sun.COM>
parents: 12296
diff changeset
   931
void
c77e20e4e046 6938089 dedup-induced latency causes FC initiator logouts/FC port resets
George Wilson <George.Wilson@Sun.COM>
parents: 12296
diff changeset
   932
fzap_prefetch(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
   933
{
c77e20e4e046 6938089 dedup-induced latency causes FC initiator logouts/FC port resets
George Wilson <George.Wilson@Sun.COM>
parents: 12296
diff changeset
   934
	uint64_t idx, blk;
c77e20e4e046 6938089 dedup-induced latency causes FC initiator logouts/FC port resets
George Wilson <George.Wilson@Sun.COM>
parents: 12296
diff changeset
   935
	zap_t *zap = zn->zn_zap;
c77e20e4e046 6938089 dedup-induced latency causes FC initiator logouts/FC port resets
George Wilson <George.Wilson@Sun.COM>
parents: 12296
diff changeset
   936
	int bs;
c77e20e4e046 6938089 dedup-induced latency causes FC initiator logouts/FC port resets
George Wilson <George.Wilson@Sun.COM>
parents: 12296
diff changeset
   937
c77e20e4e046 6938089 dedup-induced latency causes FC initiator logouts/FC port resets
George Wilson <George.Wilson@Sun.COM>
parents: 12296
diff changeset
   938
	idx = ZAP_HASH_IDX(zn->zn_hash,
c77e20e4e046 6938089 dedup-induced latency causes FC initiator logouts/FC port resets
George Wilson <George.Wilson@Sun.COM>
parents: 12296
diff changeset
   939
	    zap->zap_f.zap_phys->zap_ptrtbl.zt_shift);
c77e20e4e046 6938089 dedup-induced latency causes FC initiator logouts/FC port resets
George Wilson <George.Wilson@Sun.COM>
parents: 12296
diff changeset
   940
	if (zap_idx_to_blk(zap, idx, &blk) != 0)
c77e20e4e046 6938089 dedup-induced latency causes FC initiator logouts/FC port resets
George Wilson <George.Wilson@Sun.COM>
parents: 12296
diff changeset
   941
		return;
c77e20e4e046 6938089 dedup-induced latency causes FC initiator logouts/FC port resets
George Wilson <George.Wilson@Sun.COM>
parents: 12296
diff changeset
   942
	bs = FZAP_BLOCK_SHIFT(zap);
c77e20e4e046 6938089 dedup-induced latency causes FC initiator logouts/FC port resets
George Wilson <George.Wilson@Sun.COM>
parents: 12296
diff changeset
   943
	dmu_prefetch(zap->zap_objset, zap->zap_object, blk << bs, 1 << bs);
c77e20e4e046 6938089 dedup-induced latency causes FC initiator logouts/FC port resets
George Wilson <George.Wilson@Sun.COM>
parents: 12296
diff changeset
   944
}
c77e20e4e046 6938089 dedup-induced latency causes FC initiator logouts/FC port resets
George Wilson <George.Wilson@Sun.COM>
parents: 12296
diff changeset
   945
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
   946
/*
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
   947
 * Helper functions for consumers.
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
   948
 */
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
   949
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12450
diff changeset
   950
uint64_t
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12450
diff changeset
   951
zap_create_link(objset_t *os, dmu_object_type_t ot, uint64_t parent_obj,
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12450
diff changeset
   952
    const char *name, dmu_tx_t *tx)
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12450
diff changeset
   953
{
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12450
diff changeset
   954
	uint64_t new_obj;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12450
diff changeset
   955
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12450
diff changeset
   956
	VERIFY((new_obj = zap_create(os, ot, DMU_OT_NONE, 0, tx)) > 0);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12450
diff changeset
   957
	VERIFY(zap_add(os, parent_obj, name, sizeof (uint64_t), 1, &new_obj,
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12450
diff changeset
   958
	    tx) == 0);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12450
diff changeset
   959
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12450
diff changeset
   960
	return (new_obj);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12450
diff changeset
   961
}
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12450
diff changeset
   962
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   963
int
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 2856
diff changeset
   964
zap_value_search(objset_t *os, uint64_t zapobj, uint64_t value, uint64_t mask,
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 2856
diff changeset
   965
    char *name)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   966
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   967
	zap_cursor_t zc;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   968
	zap_attribute_t *za;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   969
	int err;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   970
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 2856
diff changeset
   971
	if (mask == 0)
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 2856
diff changeset
   972
		mask = -1ULL;
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 2856
diff changeset
   973
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   974
	za = kmem_alloc(sizeof (zap_attribute_t), KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   975
	for (zap_cursor_init(&zc, os, zapobj);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   976
	    (err = zap_cursor_retrieve(&zc, za)) == 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   977
	    zap_cursor_advance(&zc)) {
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 2856
diff changeset
   978
		if ((za->za_first_integer & mask) == (value & mask)) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   979
			(void) strcpy(name, za->za_name);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   980
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   981
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   982
	}
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
   983
	zap_cursor_fini(&zc);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   984
	kmem_free(za, sizeof (zap_attribute_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   985
	return (err);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   986
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   987
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
   988
int
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
   989
zap_join(objset_t *os, uint64_t fromobj, uint64_t intoobj, dmu_tx_t *tx)
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
   990
{
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
   991
	zap_cursor_t zc;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
   992
	zap_attribute_t za;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
   993
	int err;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
   994
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
   995
	for (zap_cursor_init(&zc, os, fromobj);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
   996
	    zap_cursor_retrieve(&zc, &za) == 0;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
   997
	    (void) zap_cursor_advance(&zc)) {
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
   998
		if (za.za_integer_length != 8 || za.za_num_integers != 1)
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
   999
			return (EINVAL);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
  1000
		err = zap_add(os, intoobj, za.za_name,
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
  1001
		    8, 1, &za.za_first_integer, tx);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
  1002
		if (err)
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
  1003
			return (err);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
  1004
	}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
  1005
	zap_cursor_fini(&zc);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
  1006
	return (0);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
  1007
}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
  1008
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
  1009
int
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1010
zap_join_key(objset_t *os, uint64_t fromobj, uint64_t intoobj,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1011
    uint64_t value, dmu_tx_t *tx)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1012
{
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1013
	zap_cursor_t zc;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1014
	zap_attribute_t za;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1015
	int err;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1016
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1017
	for (zap_cursor_init(&zc, os, fromobj);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1018
	    zap_cursor_retrieve(&zc, &za) == 0;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1019
	    (void) zap_cursor_advance(&zc)) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1020
		if (za.za_integer_length != 8 || za.za_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
  1021
			return (EINVAL);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1022
		err = zap_add(os, intoobj, za.za_name,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1023
		    8, 1, &value, tx);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1024
		if (err)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1025
			return (err);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1026
	}
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1027
	zap_cursor_fini(&zc);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1028
	return (0);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1029
}
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1030
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1031
int
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1032
zap_join_increment(objset_t *os, uint64_t fromobj, uint64_t intoobj,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1033
    dmu_tx_t *tx)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1034
{
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1035
	zap_cursor_t zc;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1036
	zap_attribute_t za;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1037
	int err;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1038
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1039
	for (zap_cursor_init(&zc, os, fromobj);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1040
	    zap_cursor_retrieve(&zc, &za) == 0;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1041
	    (void) zap_cursor_advance(&zc)) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1042
		uint64_t delta = 0;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1043
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1044
		if (za.za_integer_length != 8 || za.za_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
  1045
			return (EINVAL);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1046
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1047
		err = zap_lookup(os, intoobj, za.za_name, 8, 1, &delta);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1048
		if (err != 0 && err != ENOENT)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1049
			return (err);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1050
		delta += za.za_first_integer;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1051
		err = zap_update(os, intoobj, za.za_name, 8, 1, &delta, tx);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1052
		if (err)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1053
			return (err);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1054
	}
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1055
	zap_cursor_fini(&zc);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1056
	return (0);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1057
}
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1058
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1059
int
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
  1060
zap_add_int(objset_t *os, uint64_t obj, uint64_t value, dmu_tx_t *tx)
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
  1061
{
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
  1062
	char name[20];
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
  1063
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
  1064
	(void) snprintf(name, sizeof (name), "%llx", (longlong_t)value);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
  1065
	return (zap_add(os, obj, name, 8, 1, &value, tx));
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
  1066
}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
  1067
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
  1068
int
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
  1069
zap_remove_int(objset_t *os, uint64_t obj, uint64_t value, dmu_tx_t *tx)
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
  1070
{
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
  1071
	char name[20];
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
  1072
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
  1073
	(void) snprintf(name, sizeof (name), "%llx", (longlong_t)value);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
  1074
	return (zap_remove(os, obj, name, tx));
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
  1075
}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
  1076
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
  1077
int
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
  1078
zap_lookup_int(objset_t *os, uint64_t obj, uint64_t value)
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
  1079
{
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
  1080
	char name[20];
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
  1081
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
  1082
	(void) snprintf(name, sizeof (name), "%llx", (longlong_t)value);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
  1083
	return (zap_lookup(os, obj, name, 8, 1, &value));
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5498
diff changeset
  1084
}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1085
10407
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9653
diff changeset
  1086
int
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1087
zap_add_int_key(objset_t *os, uint64_t obj,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1088
    uint64_t key, uint64_t value, dmu_tx_t *tx)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1089
{
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1090
	char name[20];
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1091
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1092
	(void) snprintf(name, sizeof (name), "%llx", (longlong_t)key);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1093
	return (zap_add(os, obj, name, 8, 1, &value, tx));
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1094
}
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1095
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1096
int
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1097
zap_lookup_int_key(objset_t *os, uint64_t obj, uint64_t key, uint64_t *valuep)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1098
{
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1099
	char name[20];
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1100
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1101
	(void) snprintf(name, sizeof (name), "%llx", (longlong_t)key);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1102
	return (zap_lookup(os, obj, name, 8, 1, valuep));
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1103
}
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1104
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1105
int
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1106
zap_increment(objset_t *os, uint64_t obj, const char *name, int64_t delta,
10407
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9653
diff changeset
  1107
    dmu_tx_t *tx)
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9653
diff changeset
  1108
{
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9653
diff changeset
  1109
	uint64_t value = 0;
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9653
diff changeset
  1110
	int err;
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9653
diff changeset
  1111
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9653
diff changeset
  1112
	if (delta == 0)
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9653
diff changeset
  1113
		return (0);
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9653
diff changeset
  1114
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9653
diff changeset
  1115
	err = zap_lookup(os, obj, name, 8, 1, &value);
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9653
diff changeset
  1116
	if (err != 0 && err != ENOENT)
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9653
diff changeset
  1117
		return (err);
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9653
diff changeset
  1118
	value += delta;
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9653
diff changeset
  1119
	if (value == 0)
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9653
diff changeset
  1120
		err = zap_remove(os, obj, name, tx);
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9653
diff changeset
  1121
	else
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9653
diff changeset
  1122
		err = zap_update(os, obj, name, 8, 1, &value, tx);
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9653
diff changeset
  1123
	return (err);
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9653
diff changeset
  1124
}
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9653
diff changeset
  1125
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1126
int
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1127
zap_increment_int(objset_t *os, uint64_t obj, uint64_t key, int64_t delta,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1128
    dmu_tx_t *tx)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1129
{
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1130
	char name[20];
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1131
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1132
	(void) snprintf(name, sizeof (name), "%llx", (longlong_t)key);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1133
	return (zap_increment(os, obj, name, delta, tx));
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12285
diff changeset
  1134
}
10407
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9653
diff changeset
  1135
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1136
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1137
 * Routines for iterating over the attributes.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1138
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1139
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1140
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1141
fzap_cursor_retrieve(zap_t *zap, zap_cursor_t *zc, zap_attribute_t *za)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1142
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1143
	int err = ENOENT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1144
	zap_entry_handle_t zeh;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1145
	zap_leaf_t *l;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1146
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1147
	/* retrieve the next entry at or after zc_hash/zc_cd */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1148
	/* if no entry, return ENOENT */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1149
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1150
	if (zc->zc_leaf &&
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
  1151
	    (ZAP_HASH_IDX(zc->zc_hash,
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
  1152
	    zc->zc_leaf->l_phys->l_hdr.lh_prefix_len) !=
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
  1153
	    zc->zc_leaf->l_phys->l_hdr.lh_prefix)) {
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1154
		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
  1155
		zap_put_leaf(zc->zc_leaf);
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1156
		zc->zc_leaf = NULL;
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1157
	}
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1158
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1159
again:
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1160
	if (zc->zc_leaf == NULL) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
  1161
		err = zap_deref_leaf(zap, zc->zc_hash, NULL, RW_READER,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
  1162
		    &zc->zc_leaf);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
  1163
		if (err != 0)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
  1164
			return (err);
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1165
	} else {
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1166
		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
  1167
	}
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1168
	l = zc->zc_leaf;
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1169
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1170
	err = zap_leaf_lookup_closest(l, zc->zc_hash, zc->zc_cd, &zeh);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1171
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1172
	if (err == ENOENT) {
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
  1173
		uint64_t nocare =
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
  1174
		    (1ULL << (64 - l->l_phys->l_hdr.lh_prefix_len)) - 1;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1175
		zc->zc_hash = (zc->zc_hash & ~nocare) + nocare + 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1176
		zc->zc_cd = 0;
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
  1177
		if (l->l_phys->l_hdr.lh_prefix_len == 0 || zc->zc_hash == 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1178
			zc->zc_hash = -1ULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1179
		} else {
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1180
			zap_put_leaf(zc->zc_leaf);
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1181
			zc->zc_leaf = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1182
			goto again;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1183
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1184
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1185
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1186
	if (err == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1187
		zc->zc_hash = zeh.zeh_hash;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1188
		zc->zc_cd = zeh.zeh_cd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1189
		za->za_integer_length = zeh.zeh_integer_size;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1190
		za->za_num_integers = zeh.zeh_num_integers;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1191
		if (zeh.zeh_num_integers == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1192
			za->za_first_integer = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1193
		} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1194
			err = zap_entry_read(&zeh, 8, 1, &za->za_first_integer);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1195
			ASSERT(err == 0 || err == EOVERFLOW);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1196
		}
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10612
diff changeset
  1197
		err = zap_entry_read_name(zap, &zeh,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1198
		    sizeof (za->za_name), za->za_name);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1199
		ASSERT(err == 0);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4577
diff changeset
  1200
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4577
diff changeset
  1201
		za->za_normalization_conflict =
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4577
diff changeset
  1202
		    zap_entry_normalization_conflict(&zeh,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4577
diff changeset
  1203
		    NULL, za->za_name, zap);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1204
	}
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1205
	rw_exit(&zc->zc_leaf->l_rwlock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1206
	return (err);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1207
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1208
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1209
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1210
zap_stats_ptrtbl(zap_t *zap, uint64_t *tbl, int len, zap_stats_t *zs)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1211
{
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
  1212
	int i, err;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1213
	uint64_t lastblk = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1214
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1215
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1216
	 * NB: if a leaf has more pointers than an entire ptrtbl block
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1217
	 * can hold, then it'll be accounted for more than once, since
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1218
	 * we won't have lastblk.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1219
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1220
	for (i = 0; i < len; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1221
		zap_leaf_t *l;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1222
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1223
		if (tbl[i] == lastblk)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1224
			continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1225
		lastblk = tbl[i];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1226
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
  1227
		err = zap_get_leaf_byblk(zap, tbl[i], NULL, RW_READER, &l);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
  1228
		if (err == 0) {
1578
1fd8ab638fc0 6389897 remove zap leaf chaining code as it is never used
ahrens
parents: 1544
diff changeset
  1229
			zap_leaf_stats(zap, l, zs);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
  1230
			zap_put_leaf(l);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
  1231
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1232
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1233
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1234
10612
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10431
diff changeset
  1235
int
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10431
diff changeset
  1236
fzap_cursor_move_to_key(zap_cursor_t *zc, zap_name_t *zn)
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10431
diff changeset
  1237
{
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10431
diff changeset
  1238
	int err;
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10431
diff changeset
  1239
	zap_leaf_t *l;
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10431
diff changeset
  1240
	zap_entry_handle_t zeh;
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10431
diff changeset
  1241
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
  1242
	if (zn->zn_key_orig_numints * zn->zn_key_intlen > ZAP_MAXNAMELEN)
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10922
diff changeset
  1243
		return (ENAMETOOLONG);
10612
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10431
diff changeset
  1244
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10431
diff changeset
  1245
	err = zap_deref_leaf(zc->zc_zap, zn->zn_hash, NULL, RW_READER, &l);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10431
diff changeset
  1246
	if (err != 0)
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10431
diff changeset
  1247
		return (err);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10431
diff changeset
  1248
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10431
diff changeset
  1249
	err = zap_leaf_lookup(l, zn, &zeh);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10431
diff changeset
  1250
	if (err != 0)
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10431
diff changeset
  1251
		return (err);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10431
diff changeset
  1252
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10431
diff changeset
  1253
	zc->zc_leaf = l;
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10431
diff changeset
  1254
	zc->zc_hash = zeh.zeh_hash;
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10431
diff changeset
  1255
	zc->zc_cd = zeh.zeh_cd;
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10431
diff changeset
  1256
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10431
diff changeset
  1257
	return (err);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10431
diff changeset
  1258
}
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10431
diff changeset
  1259
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1260
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1261
fzap_get_stats(zap_t *zap, zap_stats_t *zs)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1262
{
1491
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
  1263
	int bs = FZAP_BLOCK_SHIFT(zap);
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
  1264
	zs->zs_blocksize = 1ULL << bs;
1632
7d486ebd46b7 6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents: 1578
diff changeset
  1265
7d486ebd46b7 6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents: 1578
diff changeset
  1266
	/*
7d486ebd46b7 6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents: 1578
diff changeset
  1267
	 * Set zap_phys_t fields
7d486ebd46b7 6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents: 1578
diff changeset
  1268
	 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1269
	zs->zs_num_leafs = zap->zap_f.zap_phys->zap_num_leafs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1270
	zs->zs_num_entries = zap->zap_f.zap_phys->zap_num_entries;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1271
	zs->zs_num_blocks = zap->zap_f.zap_phys->zap_freeblk;
1632
7d486ebd46b7 6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents: 1578
diff changeset
  1272
	zs->zs_block_type = zap->zap_f.zap_phys->zap_block_type;
7d486ebd46b7 6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents: 1578
diff changeset
  1273
	zs->zs_magic = zap->zap_f.zap_phys->zap_magic;
7d486ebd46b7 6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents: 1578
diff changeset
  1274
	zs->zs_salt = zap->zap_f.zap_phys->zap_salt;
7d486ebd46b7 6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents: 1578
diff changeset
  1275
7d486ebd46b7 6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents: 1578
diff changeset
  1276
	/*
7d486ebd46b7 6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents: 1578
diff changeset
  1277
	 * Set zap_ptrtbl fields
7d486ebd46b7 6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents: 1578
diff changeset
  1278
	 */
7d486ebd46b7 6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents: 1578
diff changeset
  1279
	zs->zs_ptrtbl_len = 1ULL << zap->zap_f.zap_phys->zap_ptrtbl.zt_shift;
7d486ebd46b7 6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents: 1578
diff changeset
  1280
	zs->zs_ptrtbl_nextblk = zap->zap_f.zap_phys->zap_ptrtbl.zt_nextblk;
7d486ebd46b7 6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents: 1578
diff changeset
  1281
	zs->zs_ptrtbl_blks_copied =
7d486ebd46b7 6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents: 1578
diff changeset
  1282
	    zap->zap_f.zap_phys->zap_ptrtbl.zt_blks_copied;
7d486ebd46b7 6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents: 1578
diff changeset
  1283
	zs->zs_ptrtbl_zt_blk = zap->zap_f.zap_phys->zap_ptrtbl.zt_blk;
7d486ebd46b7 6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents: 1578
diff changeset
  1284
	zs->zs_ptrtbl_zt_numblks = zap->zap_f.zap_phys->zap_ptrtbl.zt_numblks;
7d486ebd46b7 6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents: 1578
diff changeset
  1285
	zs->zs_ptrtbl_zt_shift = zap->zap_f.zap_phys->zap_ptrtbl.zt_shift;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1286
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1287
	if (zap->zap_f.zap_phys->zap_ptrtbl.zt_numblks == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1288
		/* the ptrtbl is entirely in the header block. */
1491
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
  1289
		zap_stats_ptrtbl(zap, &ZAP_EMBEDDED_PTRTBL_ENT(zap, 0),
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
  1290
		    1 << ZAP_EMBEDDED_PTRTBL_SHIFT(zap), zs);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1291
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1292
		int b;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1293
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1294
		dmu_prefetch(zap->zap_objset, zap->zap_object,
1491
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
  1295
		    zap->zap_f.zap_phys->zap_ptrtbl.zt_blk << bs,
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 885
diff changeset
  1296
		    zap->zap_f.zap_phys->zap_ptrtbl.zt_numblks << bs);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1297
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1298
		for (b = 0; b < zap->zap_f.zap_phys->zap_ptrtbl.zt_numblks;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1299
		    b++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1300
			dmu_buf_t *db;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
  1301
			int err;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1302
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
  1303
			err = dmu_buf_hold(zap->zap_objset, zap->zap_object,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
  1304
			    (zap->zap_f.zap_phys->zap_ptrtbl.zt_blk + b) << bs,
12285
d736d62dcca2 6944833 Avoid prefetching dbufs in dmu_sync() path
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11165
diff changeset
  1305
			    FTAG, &db, DMU_READ_NO_PREFETCH);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
  1306
			if (err == 0) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
  1307
				zap_stats_ptrtbl(zap, db->db_data,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
  1308
				    1<<(bs-3), zs);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
  1309
				dmu_buf_rele(db, FTAG);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
  1310
			}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1311
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1312
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1313
}
9653
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1314
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1315
int
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1316
fzap_count_write(zap_name_t *zn, int add, uint64_t *towrite,
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1317
    uint64_t *tooverwrite)
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1318
{
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1319
	zap_t *zap = zn->zn_zap;
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1320
	zap_leaf_t *l;
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1321
	int err;
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1322
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1323
	/*
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1324
	 * Account for the header block of the fatzap.
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1325
	 */
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1326
	if (!add && dmu_buf_freeable(zap->zap_dbuf)) {
10431
a4572ce3df84 6870347 assertion failure in dmu_tx_willuse_space(): refcount_count(&tx->tx_space_written) + delta <= tx->tx
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 10407
diff changeset
  1327
		*tooverwrite += zap->zap_dbuf->db_size;
9653
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1328
	} else {
10431
a4572ce3df84 6870347 assertion failure in dmu_tx_willuse_space(): refcount_count(&tx->tx_space_written) + delta <= tx->tx
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 10407
diff changeset
  1329
		*towrite += zap->zap_dbuf->db_size;
9653
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1330
	}
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1331
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1332
	/*
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1333
	 * Account for the pointer table blocks.
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1334
	 * If we are adding we need to account for the following cases :
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1335
	 * - If the pointer table is embedded, this operation could force an
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1336
	 *   external pointer table.
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1337
	 * - If this already has an external pointer table 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: 9643
diff changeset
  1338
	 *   could extend the table.
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1339
	 */
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1340
	if (add) {
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1341
		if (zap->zap_f.zap_phys->zap_ptrtbl.zt_blk == 0)
10431
a4572ce3df84 6870347 assertion failure in dmu_tx_willuse_space(): refcount_count(&tx->tx_space_written) + delta <= tx->tx
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 10407
diff changeset
  1342
			*towrite += zap->zap_dbuf->db_size;
9653
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1343
		else
10431
a4572ce3df84 6870347 assertion failure in dmu_tx_willuse_space(): refcount_count(&tx->tx_space_written) + delta <= tx->tx
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 10407
diff changeset
  1344
			*towrite += (zap->zap_dbuf->db_size * 3);
9653
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1345
	}
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1346
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1347
	/*
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1348
	 * Now, check if the block containing leaf is freeable
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1349
	 * and account accordingly.
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1350
	 */
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1351
	err = zap_deref_leaf(zap, zn->zn_hash, NULL, RW_READER, &l);
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1352
	if (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: 9643
diff changeset
  1353
		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: 9643
diff changeset
  1354
	}
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1355
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1356
	if (!add && dmu_buf_freeable(l->l_dbuf)) {
10431
a4572ce3df84 6870347 assertion failure in dmu_tx_willuse_space(): refcount_count(&tx->tx_space_written) + delta <= tx->tx
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 10407
diff changeset
  1357
		*tooverwrite += l->l_dbuf->db_size;
9653
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1358
	} else {
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1359
		/*
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1360
		 * If this an add operation, the leaf block could split.
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1361
		 * Hence, we need to account for an additional leaf block.
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1362
		 */
10431
a4572ce3df84 6870347 assertion failure in dmu_tx_willuse_space(): refcount_count(&tx->tx_space_written) + delta <= tx->tx
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 10407
diff changeset
  1363
		*towrite += (add ? 2 : 1) * l->l_dbuf->db_size;
9653
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1364
	}
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1365
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1366
	zap_put_leaf(l);
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1367
	return (0);
a70048a304d1 6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 9643
diff changeset
  1368
}