OpenZFS 9328 - zap code can take advantage of c99

The ZAP code was written before we allowed c99 in the Solaris kernel. We
should change it to take advantage of being able to declare variables where
they are first used. This reduces variable scope and means less scrolling
to find the type of variables.

Authored by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Steve Gonczi <steve.gonczi@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed-by: George Melikov <mail@gmelikov.ru>
Approved by: Dan McDonald <danmcd@joyent.com>
Ported-by: Brian Behlendorf <behlendorf1@llnl.gov>

OpenZFS-issue: https://illumos.org/issues/9328
OpenZFS-commit: https://github.com/openzfs/openzfs/commit/76ead05
Closes #7578
This commit is contained in:
Matthew Ahrens 2018-05-30 11:16:54 -07:00 committed by Brian Behlendorf
parent 74d42600d8
commit d2a12f9e2a
3 changed files with 224 additions and 328 deletions

View File

@ -58,9 +58,7 @@ static uint64_t zap_allocate_blocks(zap_t *zap, int nblocks);
void void
fzap_byteswap(void *vbuf, size_t size) fzap_byteswap(void *vbuf, size_t size)
{ {
uint64_t block_type; uint64_t block_type = *(uint64_t *)vbuf;
block_type = *(uint64_t *)vbuf;
if (block_type == ZBT_LEAF || block_type == BSWAP_64(ZBT_LEAF)) if (block_type == ZBT_LEAF || block_type == BSWAP_64(ZBT_LEAF))
zap_leaf_byteswap(vbuf, size); zap_leaf_byteswap(vbuf, size);
@ -73,11 +71,6 @@ fzap_byteswap(void *vbuf, size_t size)
void void
fzap_upgrade(zap_t *zap, dmu_tx_t *tx, zap_flags_t flags) fzap_upgrade(zap_t *zap, dmu_tx_t *tx, zap_flags_t flags)
{ {
dmu_buf_t *db;
zap_leaf_t *l;
int i;
zap_phys_t *zp;
ASSERT(RW_WRITE_HELD(&zap->zap_rwlock)); ASSERT(RW_WRITE_HELD(&zap->zap_rwlock));
zap->zap_ismicro = FALSE; zap->zap_ismicro = FALSE;
@ -87,7 +80,7 @@ fzap_upgrade(zap_t *zap, dmu_tx_t *tx, zap_flags_t flags)
mutex_init(&zap->zap_f.zap_num_entries_mtx, 0, MUTEX_DEFAULT, 0); mutex_init(&zap->zap_f.zap_num_entries_mtx, 0, MUTEX_DEFAULT, 0);
zap->zap_f.zap_block_shift = highbit64(zap->zap_dbuf->db_size) - 1; zap->zap_f.zap_block_shift = highbit64(zap->zap_dbuf->db_size) - 1;
zp = zap_f_phys(zap); zap_phys_t *zp = zap_f_phys(zap);
/* /*
* explicitly zero it since it might be coming from an * explicitly zero it since it might be coming from an
* initialized microzap * initialized microzap
@ -106,17 +99,18 @@ fzap_upgrade(zap_t *zap, dmu_tx_t *tx, zap_flags_t flags)
zp->zap_flags = flags; zp->zap_flags = flags;
/* block 1 will be the first leaf */ /* block 1 will be the first leaf */
for (i = 0; i < (1<<zp->zap_ptrtbl.zt_shift); i++) for (int i = 0; i < (1<<zp->zap_ptrtbl.zt_shift); i++)
ZAP_EMBEDDED_PTRTBL_ENT(zap, i) = 1; ZAP_EMBEDDED_PTRTBL_ENT(zap, i) = 1;
/* /*
* set up block 1 - the first leaf * set up block 1 - the first leaf
*/ */
VERIFY(0 == dmu_buf_hold(zap->zap_objset, zap->zap_object, dmu_buf_t *db;
VERIFY0(dmu_buf_hold(zap->zap_objset, zap->zap_object,
1<<FZAP_BLOCK_SHIFT(zap), FTAG, &db, DMU_READ_NO_PREFETCH)); 1<<FZAP_BLOCK_SHIFT(zap), FTAG, &db, DMU_READ_NO_PREFETCH));
dmu_buf_will_dirty(db, tx); dmu_buf_will_dirty(db, tx);
l = kmem_zalloc(sizeof (zap_leaf_t), KM_SLEEP); zap_leaf_t *l = kmem_zalloc(sizeof (zap_leaf_t), KM_SLEEP);
l->l_dbuf = db; l->l_dbuf = db;
zap_leaf_init(l, zp->zap_normflags != 0); zap_leaf_init(l, zp->zap_normflags != 0);
@ -146,9 +140,7 @@ zap_table_grow(zap_t *zap, zap_table_phys_t *tbl,
void (*transfer_func)(const uint64_t *src, uint64_t *dst, int n), void (*transfer_func)(const uint64_t *src, uint64_t *dst, int n),
dmu_tx_t *tx) dmu_tx_t *tx)
{ {
uint64_t b, newblk; uint64_t newblk;
dmu_buf_t *db_old, *db_new;
int err;
int bs = FZAP_BLOCK_SHIFT(zap); int bs = FZAP_BLOCK_SHIFT(zap);
int hepb = 1<<(bs-4); int hepb = 1<<(bs-4);
/* hepb = half the number of entries in a block */ /* hepb = half the number of entries in a block */
@ -172,21 +164,23 @@ zap_table_grow(zap_t *zap, zap_table_phys_t *tbl,
* Copy the ptrtbl from the old to new location. * Copy the ptrtbl from the old to new location.
*/ */
b = tbl->zt_blks_copied; uint64_t b = tbl->zt_blks_copied;
err = dmu_buf_hold(zap->zap_objset, zap->zap_object, dmu_buf_t *db_old;
int err = dmu_buf_hold(zap->zap_objset, zap->zap_object,
(tbl->zt_blk + b) << bs, FTAG, &db_old, DMU_READ_NO_PREFETCH); (tbl->zt_blk + b) << bs, FTAG, &db_old, DMU_READ_NO_PREFETCH);
if (err) if (err != 0)
return (err); return (err);
/* first half of entries in old[b] go to new[2*b+0] */ /* first half of entries in old[b] go to new[2*b+0] */
VERIFY(0 == dmu_buf_hold(zap->zap_objset, zap->zap_object, dmu_buf_t *db_new;
VERIFY0(dmu_buf_hold(zap->zap_objset, zap->zap_object,
(newblk + 2*b+0) << bs, FTAG, &db_new, DMU_READ_NO_PREFETCH)); (newblk + 2*b+0) << bs, FTAG, &db_new, DMU_READ_NO_PREFETCH));
dmu_buf_will_dirty(db_new, tx); dmu_buf_will_dirty(db_new, tx);
transfer_func(db_old->db_data, db_new->db_data, hepb); transfer_func(db_old->db_data, db_new->db_data, hepb);
dmu_buf_rele(db_new, FTAG); dmu_buf_rele(db_new, FTAG);
/* second half of entries in old[b] go to new[2*b+1] */ /* second half of entries in old[b] go to new[2*b+1] */
VERIFY(0 == dmu_buf_hold(zap->zap_objset, zap->zap_object, VERIFY0(dmu_buf_hold(zap->zap_objset, zap->zap_object,
(newblk + 2*b+1) << bs, FTAG, &db_new, DMU_READ_NO_PREFETCH)); (newblk + 2*b+1) << bs, FTAG, &db_new, DMU_READ_NO_PREFETCH));
dmu_buf_will_dirty(db_new, tx); dmu_buf_will_dirty(db_new, tx);
transfer_func((uint64_t *)db_old->db_data + hepb, transfer_func((uint64_t *)db_old->db_data + hepb,
@ -221,22 +215,20 @@ static int
zap_table_store(zap_t *zap, zap_table_phys_t *tbl, uint64_t idx, uint64_t val, zap_table_store(zap_t *zap, zap_table_phys_t *tbl, uint64_t idx, uint64_t val,
dmu_tx_t *tx) dmu_tx_t *tx)
{ {
int err;
uint64_t blk, off;
int bs = FZAP_BLOCK_SHIFT(zap); int bs = FZAP_BLOCK_SHIFT(zap);
dmu_buf_t *db;
ASSERT(RW_LOCK_HELD(&zap->zap_rwlock)); ASSERT(RW_LOCK_HELD(&zap->zap_rwlock));
ASSERT(tbl->zt_blk != 0); ASSERT(tbl->zt_blk != 0);
dprintf("storing %llx at index %llx\n", val, idx); dprintf("storing %llx at index %llx\n", val, idx);
blk = idx >> (bs-3); uint64_t blk = idx >> (bs-3);
off = idx & ((1<<(bs-3))-1); uint64_t off = idx & ((1<<(bs-3))-1);
err = dmu_buf_hold(zap->zap_objset, zap->zap_object, dmu_buf_t *db;
int err = dmu_buf_hold(zap->zap_objset, zap->zap_object,
(tbl->zt_blk + blk) << bs, FTAG, &db, DMU_READ_NO_PREFETCH); (tbl->zt_blk + blk) << bs, FTAG, &db, DMU_READ_NO_PREFETCH);
if (err) if (err != 0)
return (err); return (err);
dmu_buf_will_dirty(db, tx); dmu_buf_will_dirty(db, tx);
@ -249,7 +241,7 @@ zap_table_store(zap_t *zap, zap_table_phys_t *tbl, uint64_t idx, uint64_t val,
err = dmu_buf_hold(zap->zap_objset, zap->zap_object, err = dmu_buf_hold(zap->zap_objset, zap->zap_object,
(tbl->zt_nextblk + blk2) << bs, FTAG, &db2, (tbl->zt_nextblk + blk2) << bs, FTAG, &db2,
DMU_READ_NO_PREFETCH); DMU_READ_NO_PREFETCH);
if (err) { if (err != 0) {
dmu_buf_rele(db, FTAG); dmu_buf_rele(db, FTAG);
return (err); return (err);
} }
@ -268,27 +260,24 @@ zap_table_store(zap_t *zap, zap_table_phys_t *tbl, uint64_t idx, uint64_t val,
static int static int
zap_table_load(zap_t *zap, zap_table_phys_t *tbl, uint64_t idx, uint64_t *valp) zap_table_load(zap_t *zap, zap_table_phys_t *tbl, uint64_t idx, uint64_t *valp)
{ {
uint64_t blk, off;
int err;
dmu_buf_t *db;
dnode_t *dn;
int bs = FZAP_BLOCK_SHIFT(zap); int bs = FZAP_BLOCK_SHIFT(zap);
ASSERT(RW_LOCK_HELD(&zap->zap_rwlock)); ASSERT(RW_LOCK_HELD(&zap->zap_rwlock));
blk = idx >> (bs-3); uint64_t blk = idx >> (bs-3);
off = idx & ((1<<(bs-3))-1); uint64_t off = idx & ((1<<(bs-3))-1);
/* /*
* Note: this is equivalent to dmu_buf_hold(), but we use * Note: this is equivalent to dmu_buf_hold(), but we use
* _dnode_enter / _by_dnode because it's faster because we don't * _dnode_enter / _by_dnode because it's faster because we don't
* have to hold the dnode. * have to hold the dnode.
*/ */
dn = dmu_buf_dnode_enter(zap->zap_dbuf); dnode_t *dn = dmu_buf_dnode_enter(zap->zap_dbuf);
err = dmu_buf_hold_by_dnode(dn, dmu_buf_t *db;
int err = dmu_buf_hold_by_dnode(dn,
(tbl->zt_blk + blk) << bs, FTAG, &db, DMU_READ_NO_PREFETCH); (tbl->zt_blk + blk) << bs, FTAG, &db, DMU_READ_NO_PREFETCH);
dmu_buf_dnode_exit(zap->zap_dbuf); dmu_buf_dnode_exit(zap->zap_dbuf);
if (err) if (err != 0)
return (err); return (err);
*valp = ((uint64_t *)db->db_data)[off]; *valp = ((uint64_t *)db->db_data)[off];
dmu_buf_rele(db, FTAG); dmu_buf_rele(db, FTAG);
@ -319,11 +308,10 @@ zap_table_load(zap_t *zap, zap_table_phys_t *tbl, uint64_t idx, uint64_t *valp)
static void static void
zap_ptrtbl_transfer(const uint64_t *src, uint64_t *dst, int n) zap_ptrtbl_transfer(const uint64_t *src, uint64_t *dst, int n)
{ {
int i; for (int i = 0; i < n; i++) {
for (i = 0; i < n; i++) {
uint64_t lb = src[i]; uint64_t lb = src[i];
dst[2*i+0] = lb; dst[2 * i + 0] = lb;
dst[2*i+1] = lb; dst[2 * i + 1] = lb;
} }
} }
@ -345,19 +333,16 @@ zap_grow_ptrtbl(zap_t *zap, dmu_tx_t *tx)
* stored in the header block). Give it its own entire * stored in the header block). Give it its own entire
* block, which will double the size of the ptrtbl. * block, which will double the size of the ptrtbl.
*/ */
uint64_t newblk;
dmu_buf_t *db_new;
int err;
ASSERT3U(zap_f_phys(zap)->zap_ptrtbl.zt_shift, ==, ASSERT3U(zap_f_phys(zap)->zap_ptrtbl.zt_shift, ==,
ZAP_EMBEDDED_PTRTBL_SHIFT(zap)); ZAP_EMBEDDED_PTRTBL_SHIFT(zap));
ASSERT0(zap_f_phys(zap)->zap_ptrtbl.zt_blk); ASSERT0(zap_f_phys(zap)->zap_ptrtbl.zt_blk);
newblk = zap_allocate_blocks(zap, 1); uint64_t newblk = zap_allocate_blocks(zap, 1);
err = dmu_buf_hold(zap->zap_objset, zap->zap_object, dmu_buf_t *db_new;
int err = dmu_buf_hold(zap->zap_objset, zap->zap_object,
newblk << FZAP_BLOCK_SHIFT(zap), FTAG, &db_new, newblk << FZAP_BLOCK_SHIFT(zap), FTAG, &db_new,
DMU_READ_NO_PREFETCH); DMU_READ_NO_PREFETCH);
if (err) if (err != 0)
return (err); return (err);
dmu_buf_will_dirty(db_new, tx); dmu_buf_will_dirty(db_new, tx);
zap_ptrtbl_transfer(&ZAP_EMBEDDED_PTRTBL_ENT(zap, 0), zap_ptrtbl_transfer(&ZAP_EMBEDDED_PTRTBL_ENT(zap, 0),
@ -392,9 +377,8 @@ zap_increment_num_entries(zap_t *zap, int delta, dmu_tx_t *tx)
static uint64_t static uint64_t
zap_allocate_blocks(zap_t *zap, int nblocks) zap_allocate_blocks(zap_t *zap, int nblocks)
{ {
uint64_t newblk;
ASSERT(RW_WRITE_HELD(&zap->zap_rwlock)); ASSERT(RW_WRITE_HELD(&zap->zap_rwlock));
newblk = zap_f_phys(zap)->zap_freeblk; uint64_t newblk = zap_f_phys(zap)->zap_freeblk;
zap_f_phys(zap)->zap_freeblk += nblocks; zap_f_phys(zap)->zap_freeblk += nblocks;
return (newblk); return (newblk);
} }
@ -411,7 +395,6 @@ zap_leaf_evict_sync(void *dbu)
static zap_leaf_t * static zap_leaf_t *
zap_create_leaf(zap_t *zap, dmu_tx_t *tx) zap_create_leaf(zap_t *zap, dmu_tx_t *tx)
{ {
void *winner;
zap_leaf_t *l = kmem_zalloc(sizeof (zap_leaf_t), KM_SLEEP); zap_leaf_t *l = kmem_zalloc(sizeof (zap_leaf_t), KM_SLEEP);
ASSERT(RW_WRITE_HELD(&zap->zap_rwlock)); ASSERT(RW_WRITE_HELD(&zap->zap_rwlock));
@ -421,12 +404,11 @@ zap_create_leaf(zap_t *zap, dmu_tx_t *tx)
l->l_blkid = zap_allocate_blocks(zap, 1); l->l_blkid = zap_allocate_blocks(zap, 1);
l->l_dbuf = NULL; l->l_dbuf = NULL;
VERIFY(0 == dmu_buf_hold(zap->zap_objset, zap->zap_object, VERIFY0(dmu_buf_hold(zap->zap_objset, zap->zap_object,
l->l_blkid << FZAP_BLOCK_SHIFT(zap), NULL, &l->l_dbuf, l->l_blkid << FZAP_BLOCK_SHIFT(zap), NULL, &l->l_dbuf,
DMU_READ_NO_PREFETCH)); DMU_READ_NO_PREFETCH));
dmu_buf_init_user(&l->l_dbu, zap_leaf_evict_sync, NULL, &l->l_dbuf); dmu_buf_init_user(&l->l_dbu, zap_leaf_evict_sync, NULL, &l->l_dbuf);
winner = dmu_buf_set_user(l->l_dbuf, &l->l_dbu); VERIFY3P(NULL, ==, dmu_buf_set_user(l->l_dbuf, &l->l_dbu));
ASSERT(winner == NULL);
dmu_buf_will_dirty(l->l_dbuf, tx); dmu_buf_will_dirty(l->l_dbuf, tx);
zap_leaf_init(l, zap->zap_normflags != 0); zap_leaf_init(l, zap->zap_normflags != 0);
@ -460,11 +442,9 @@ zap_put_leaf(zap_leaf_t *l)
static zap_leaf_t * static zap_leaf_t *
zap_open_leaf(uint64_t blkid, dmu_buf_t *db) zap_open_leaf(uint64_t blkid, dmu_buf_t *db)
{ {
zap_leaf_t *l, *winner;
ASSERT(blkid != 0); ASSERT(blkid != 0);
l = kmem_zalloc(sizeof (zap_leaf_t), KM_SLEEP); zap_leaf_t *l = kmem_zalloc(sizeof (zap_leaf_t), KM_SLEEP);
rw_init(&l->l_rwlock, NULL, RW_DEFAULT, NULL); rw_init(&l->l_rwlock, NULL, RW_DEFAULT, NULL);
rw_enter(&l->l_rwlock, RW_WRITER); rw_enter(&l->l_rwlock, RW_WRITER);
l->l_blkid = blkid; l->l_blkid = blkid;
@ -472,7 +452,7 @@ zap_open_leaf(uint64_t blkid, dmu_buf_t *db)
l->l_dbuf = db; l->l_dbuf = db;
dmu_buf_init_user(&l->l_dbu, zap_leaf_evict_sync, NULL, &l->l_dbuf); dmu_buf_init_user(&l->l_dbu, zap_leaf_evict_sync, NULL, &l->l_dbuf);
winner = dmu_buf_set_user(db, &l->l_dbu); zap_leaf_t *winner = dmu_buf_set_user(db, &l->l_dbu);
rw_exit(&l->l_rwlock); rw_exit(&l->l_rwlock);
if (winner != NULL) { if (winner != NULL) {
@ -510,9 +490,6 @@ zap_get_leaf_byblk(zap_t *zap, uint64_t blkid, dmu_tx_t *tx, krw_t lt,
zap_leaf_t **lp) zap_leaf_t **lp)
{ {
dmu_buf_t *db; dmu_buf_t *db;
zap_leaf_t *l;
int bs = FZAP_BLOCK_SHIFT(zap);
int err;
ASSERT(RW_LOCK_HELD(&zap->zap_rwlock)); ASSERT(RW_LOCK_HELD(&zap->zap_rwlock));
@ -526,11 +503,12 @@ zap_get_leaf_byblk(zap_t *zap, uint64_t blkid, dmu_tx_t *tx, krw_t lt,
if (blkid == 0) if (blkid == 0)
return (SET_ERROR(ENOENT)); return (SET_ERROR(ENOENT));
int bs = FZAP_BLOCK_SHIFT(zap);
dnode_t *dn = dmu_buf_dnode_enter(zap->zap_dbuf); dnode_t *dn = dmu_buf_dnode_enter(zap->zap_dbuf);
err = dmu_buf_hold_by_dnode(dn, int err = dmu_buf_hold_by_dnode(dn,
blkid << bs, NULL, &db, DMU_READ_NO_PREFETCH); blkid << bs, NULL, &db, DMU_READ_NO_PREFETCH);
dmu_buf_dnode_exit(zap->zap_dbuf); dmu_buf_dnode_exit(zap->zap_dbuf);
if (err) if (err != 0)
return (err); return (err);
ASSERT3U(db->db_object, ==, zap->zap_object); ASSERT3U(db->db_object, ==, zap->zap_object);
@ -538,7 +516,7 @@ zap_get_leaf_byblk(zap_t *zap, uint64_t blkid, dmu_tx_t *tx, krw_t lt,
ASSERT3U(db->db_size, ==, 1 << bs); ASSERT3U(db->db_size, ==, 1 << bs);
ASSERT(blkid != 0); ASSERT(blkid != 0);
l = dmu_buf_get_user(db); zap_leaf_t *l = dmu_buf_get_user(db);
if (l == NULL) if (l == NULL)
l = zap_open_leaf(blkid, db); l = zap_open_leaf(blkid, db);
@ -593,8 +571,7 @@ zap_set_idx_to_blk(zap_t *zap, uint64_t idx, uint64_t blk, dmu_tx_t *tx)
static int static int
zap_deref_leaf(zap_t *zap, uint64_t h, dmu_tx_t *tx, krw_t lt, zap_leaf_t **lp) zap_deref_leaf(zap_t *zap, uint64_t h, dmu_tx_t *tx, krw_t lt, zap_leaf_t **lp)
{ {
uint64_t idx, blk; uint64_t blk;
int err;
ASSERT(zap->zap_dbuf == NULL || ASSERT(zap->zap_dbuf == NULL ||
zap_f_phys(zap) == zap->zap_dbuf->db_data); zap_f_phys(zap) == zap->zap_dbuf->db_data);
@ -605,8 +582,9 @@ zap_deref_leaf(zap_t *zap, uint64_t h, dmu_tx_t *tx, krw_t lt, zap_leaf_t **lp)
zap_f_phys(zap)->zap_magic != ZAP_MAGIC) { zap_f_phys(zap)->zap_magic != ZAP_MAGIC) {
return (SET_ERROR(EIO)); return (SET_ERROR(EIO));
} }
idx = ZAP_HASH_IDX(h, zap_f_phys(zap)->zap_ptrtbl.zt_shift);
err = zap_idx_to_blk(zap, idx, &blk); uint64_t idx = ZAP_HASH_IDX(h, zap_f_phys(zap)->zap_ptrtbl.zt_shift);
int err = zap_idx_to_blk(zap, idx, &blk);
if (err != 0) if (err != 0)
return (err); return (err);
err = zap_get_leaf_byblk(zap, blk, tx, lt, lp); err = zap_get_leaf_byblk(zap, blk, tx, lt, lp);
@ -623,9 +601,7 @@ zap_expand_leaf(zap_name_t *zn, zap_leaf_t *l,
{ {
zap_t *zap = zn->zn_zap; zap_t *zap = zn->zn_zap;
uint64_t hash = zn->zn_hash; uint64_t hash = zn->zn_hash;
zap_leaf_t *nl; int err;
int prefix_diff, i, err;
uint64_t sibling;
int old_prefix_len = zap_leaf_phys(l)->l_hdr.lh_prefix_len; int old_prefix_len = zap_leaf_phys(l)->l_hdr.lh_prefix_len;
ASSERT3U(old_prefix_len, <=, zap_f_phys(zap)->zap_ptrtbl.zt_shift); ASSERT3U(old_prefix_len, <=, zap_f_phys(zap)->zap_ptrtbl.zt_shift);
@ -645,19 +621,19 @@ zap_expand_leaf(zap_name_t *zn, zap_leaf_t *l,
err = zap_lockdir(os, object, tx, RW_WRITER, err = zap_lockdir(os, object, tx, RW_WRITER,
FALSE, FALSE, tag, &zn->zn_zap); FALSE, FALSE, tag, &zn->zn_zap);
zap = zn->zn_zap; zap = zn->zn_zap;
if (err) if (err != 0)
return (err); return (err);
ASSERT(!zap->zap_ismicro); ASSERT(!zap->zap_ismicro);
while (old_prefix_len == while (old_prefix_len ==
zap_f_phys(zap)->zap_ptrtbl.zt_shift) { zap_f_phys(zap)->zap_ptrtbl.zt_shift) {
err = zap_grow_ptrtbl(zap, tx); err = zap_grow_ptrtbl(zap, tx);
if (err) if (err != 0)
return (err); return (err);
} }
err = zap_deref_leaf(zap, hash, tx, RW_WRITER, &l); err = zap_deref_leaf(zap, hash, tx, RW_WRITER, &l);
if (err) if (err != 0)
return (err); return (err);
if (zap_leaf_phys(l)->l_hdr.lh_prefix_len != old_prefix_len) { if (zap_leaf_phys(l)->l_hdr.lh_prefix_len != old_prefix_len) {
@ -671,25 +647,26 @@ zap_expand_leaf(zap_name_t *zn, zap_leaf_t *l,
ASSERT3U(ZAP_HASH_IDX(hash, old_prefix_len), ==, ASSERT3U(ZAP_HASH_IDX(hash, old_prefix_len), ==,
zap_leaf_phys(l)->l_hdr.lh_prefix); zap_leaf_phys(l)->l_hdr.lh_prefix);
prefix_diff = zap_f_phys(zap)->zap_ptrtbl.zt_shift - int prefix_diff = zap_f_phys(zap)->zap_ptrtbl.zt_shift -
(old_prefix_len + 1); (old_prefix_len + 1);
sibling = (ZAP_HASH_IDX(hash, old_prefix_len + 1) | 1) << prefix_diff; uint64_t sibling =
(ZAP_HASH_IDX(hash, old_prefix_len + 1) | 1) << prefix_diff;
/* check for i/o errors before doing zap_leaf_split */ /* check for i/o errors before doing zap_leaf_split */
for (i = 0; i < (1ULL<<prefix_diff); i++) { for (int i = 0; i < (1ULL << prefix_diff); i++) {
uint64_t blk; uint64_t blk;
err = zap_idx_to_blk(zap, sibling+i, &blk); err = zap_idx_to_blk(zap, sibling + i, &blk);
if (err) if (err != 0)
return (err); return (err);
ASSERT3U(blk, ==, l->l_blkid); ASSERT3U(blk, ==, l->l_blkid);
} }
nl = zap_create_leaf(zap, tx); zap_leaf_t *nl = zap_create_leaf(zap, tx);
zap_leaf_split(l, nl, zap->zap_normflags != 0); zap_leaf_split(l, nl, zap->zap_normflags != 0);
/* set sibling pointers */ /* set sibling pointers */
for (i = 0; i < (1ULL << prefix_diff); i++) { for (int i = 0; i < (1ULL << prefix_diff); i++) {
err = zap_set_idx_to_blk(zap, sibling+i, nl->l_blkid, tx); err = zap_set_idx_to_blk(zap, sibling + i, nl->l_blkid, tx);
ASSERT0(err); /* we checked for i/o errors above */ ASSERT0(err); /* we checked for i/o errors above */
} }
@ -719,8 +696,6 @@ zap_put_leaf_maybe_grow_ptrtbl(zap_name_t *zn, zap_leaf_t *l,
zap_put_leaf(l); zap_put_leaf(l);
if (leaffull || zap_f_phys(zap)->zap_ptrtbl.zt_nextblk) { if (leaffull || zap_f_phys(zap)->zap_ptrtbl.zt_nextblk) {
int err;
/* /*
* We are in the middle of growing the pointer table, or * We are in the middle of growing the pointer table, or
* this leaf will soon make us grow it. * this leaf will soon make us grow it.
@ -730,10 +705,10 @@ zap_put_leaf_maybe_grow_ptrtbl(zap_name_t *zn, zap_leaf_t *l,
uint64_t zapobj = zap->zap_object; uint64_t zapobj = zap->zap_object;
zap_unlockdir(zap, tag); zap_unlockdir(zap, tag);
err = zap_lockdir(os, zapobj, tx, int err = zap_lockdir(os, zapobj, tx,
RW_WRITER, FALSE, FALSE, tag, &zn->zn_zap); RW_WRITER, FALSE, FALSE, tag, &zn->zn_zap);
zap = zn->zn_zap; zap = zn->zn_zap;
if (err) if (err != 0)
return; return;
} }
@ -774,9 +749,8 @@ fzap_checksize(uint64_t integer_size, uint64_t num_integers)
static int static int
fzap_check(zap_name_t *zn, uint64_t integer_size, uint64_t num_integers) fzap_check(zap_name_t *zn, uint64_t integer_size, uint64_t num_integers)
{ {
int err; int err = fzap_checkname(zn);
if (err != 0)
if ((err = fzap_checkname(zn)) != 0)
return (err); return (err);
return (fzap_checksize(integer_size, num_integers)); return (fzap_checksize(integer_size, num_integers));
} }
@ -790,10 +764,10 @@ fzap_lookup(zap_name_t *zn,
char *realname, int rn_len, boolean_t *ncp) char *realname, int rn_len, boolean_t *ncp)
{ {
zap_leaf_t *l; zap_leaf_t *l;
int err;
zap_entry_handle_t zeh; zap_entry_handle_t zeh;
if ((err = fzap_checkname(zn)) != 0) int err = fzap_checkname(zn);
if (err != 0)
return (err); return (err);
err = zap_deref_leaf(zn->zn_zap, zn->zn_hash, NULL, RW_READER, &l); err = zap_deref_leaf(zn->zn_zap, zn->zn_hash, NULL, RW_READER, &l);
@ -889,7 +863,8 @@ fzap_update(zap_name_t *zn,
void *tag, dmu_tx_t *tx) void *tag, dmu_tx_t *tx)
{ {
zap_leaf_t *l; zap_leaf_t *l;
int err, create; int err;
boolean_t create;
zap_entry_handle_t zeh; zap_entry_handle_t zeh;
zap_t *zap = zn->zn_zap; zap_t *zap = zn->zn_zap;
@ -942,9 +917,9 @@ fzap_length(zap_name_t *zn,
if (err != 0) if (err != 0)
goto out; goto out;
if (integer_size) if (integer_size != 0)
*integer_size = zeh.zeh_integer_size; *integer_size = zeh.zeh_integer_size;
if (num_integers) if (num_integers != 0)
*num_integers = zeh.zeh_num_integers; *num_integers = zeh.zeh_num_integers;
out: out:
zap_put_leaf(l); zap_put_leaf(l);
@ -973,15 +948,14 @@ fzap_remove(zap_name_t *zn, dmu_tx_t *tx)
void void
fzap_prefetch(zap_name_t *zn) fzap_prefetch(zap_name_t *zn)
{ {
uint64_t idx, blk; uint64_t blk;
zap_t *zap = zn->zn_zap; zap_t *zap = zn->zn_zap;
int bs;
idx = ZAP_HASH_IDX(zn->zn_hash, uint64_t idx = ZAP_HASH_IDX(zn->zn_hash,
zap_f_phys(zap)->zap_ptrtbl.zt_shift); zap_f_phys(zap)->zap_ptrtbl.zt_shift);
if (zap_idx_to_blk(zap, idx, &blk) != 0) if (zap_idx_to_blk(zap, idx, &blk) != 0)
return; return;
bs = FZAP_BLOCK_SHIFT(zap); int bs = FZAP_BLOCK_SHIFT(zap);
dmu_prefetch(zap->zap_objset, zap->zap_object, 0, blk << bs, 1 << bs, dmu_prefetch(zap->zap_objset, zap->zap_object, 0, blk << bs, 1 << bs,
ZIO_PRIORITY_SYNC_READ); ZIO_PRIORITY_SYNC_READ);
} }
@ -1003,8 +977,8 @@ zap_create_link_dnsize(objset_t *os, dmu_object_type_t ot, uint64_t parent_obj,
{ {
uint64_t new_obj; uint64_t new_obj;
VERIFY((new_obj = zap_create_dnsize(os, ot, DMU_OT_NONE, 0, new_obj = zap_create_dnsize(os, ot, DMU_OT_NONE, 0, dnodesize, tx);
dnodesize, tx)) > 0); VERIFY(new_obj != 0);
VERIFY0(zap_add(os, parent_obj, name, sizeof (uint64_t), 1, &new_obj, VERIFY0(zap_add(os, parent_obj, name, sizeof (uint64_t), 1, &new_obj,
tx)); tx));
@ -1016,13 +990,12 @@ zap_value_search(objset_t *os, uint64_t zapobj, uint64_t value, uint64_t mask,
char *name) char *name)
{ {
zap_cursor_t zc; zap_cursor_t zc;
zap_attribute_t *za;
int err; int err;
if (mask == 0) if (mask == 0)
mask = -1ULL; mask = -1ULL;
za = kmem_alloc(sizeof (zap_attribute_t), KM_SLEEP); zap_attribute_t *za = kmem_alloc(sizeof (*za), KM_SLEEP);
for (zap_cursor_init(&zc, os, zapobj); for (zap_cursor_init(&zc, os, zapobj);
(err = zap_cursor_retrieve(&zc, za)) == 0; (err = zap_cursor_retrieve(&zc, za)) == 0;
zap_cursor_advance(&zc)) { zap_cursor_advance(&zc)) {
@ -1032,7 +1005,7 @@ zap_value_search(objset_t *os, uint64_t zapobj, uint64_t value, uint64_t mask,
} }
} }
zap_cursor_fini(&zc); zap_cursor_fini(&zc);
kmem_free(za, sizeof (zap_attribute_t)); kmem_free(za, sizeof (*za));
return (err); return (err);
} }
@ -1040,23 +1013,23 @@ int
zap_join(objset_t *os, uint64_t fromobj, uint64_t intoobj, dmu_tx_t *tx) zap_join(objset_t *os, uint64_t fromobj, uint64_t intoobj, dmu_tx_t *tx)
{ {
zap_cursor_t zc; zap_cursor_t zc;
zap_attribute_t za; int err = 0;
int err;
err = 0; zap_attribute_t *za = kmem_alloc(sizeof (*za), KM_SLEEP);
for (zap_cursor_init(&zc, os, fromobj); for (zap_cursor_init(&zc, os, fromobj);
zap_cursor_retrieve(&zc, &za) == 0; zap_cursor_retrieve(&zc, za) == 0;
(void) zap_cursor_advance(&zc)) { (void) zap_cursor_advance(&zc)) {
if (za.za_integer_length != 8 || za.za_num_integers != 1) { if (za->za_integer_length != 8 || za->za_num_integers != 1) {
err = SET_ERROR(EINVAL); err = SET_ERROR(EINVAL);
break; break;
} }
err = zap_add(os, intoobj, za.za_name, err = zap_add(os, intoobj, za->za_name,
8, 1, &za.za_first_integer, tx); 8, 1, &za->za_first_integer, tx);
if (err) if (err != 0)
break; break;
} }
zap_cursor_fini(&zc); zap_cursor_fini(&zc);
kmem_free(za, sizeof (*za));
return (err); return (err);
} }
@ -1065,23 +1038,23 @@ zap_join_key(objset_t *os, uint64_t fromobj, uint64_t intoobj,
uint64_t value, dmu_tx_t *tx) uint64_t value, dmu_tx_t *tx)
{ {
zap_cursor_t zc; zap_cursor_t zc;
zap_attribute_t za; int err = 0;
int err;
err = 0; zap_attribute_t *za = kmem_alloc(sizeof (*za), KM_SLEEP);
for (zap_cursor_init(&zc, os, fromobj); for (zap_cursor_init(&zc, os, fromobj);
zap_cursor_retrieve(&zc, &za) == 0; zap_cursor_retrieve(&zc, za) == 0;
(void) zap_cursor_advance(&zc)) { (void) zap_cursor_advance(&zc)) {
if (za.za_integer_length != 8 || za.za_num_integers != 1) { if (za->za_integer_length != 8 || za->za_num_integers != 1) {
err = SET_ERROR(EINVAL); err = SET_ERROR(EINVAL);
break; break;
} }
err = zap_add(os, intoobj, za.za_name, err = zap_add(os, intoobj, za->za_name,
8, 1, &value, tx); 8, 1, &value, tx);
if (err != 0) if (err != 0)
break; break;
} }
zap_cursor_fini(&zc); zap_cursor_fini(&zc);
kmem_free(za, sizeof (*za));
return (err); return (err);
} }
@ -1090,29 +1063,29 @@ zap_join_increment(objset_t *os, uint64_t fromobj, uint64_t intoobj,
dmu_tx_t *tx) dmu_tx_t *tx)
{ {
zap_cursor_t zc; zap_cursor_t zc;
zap_attribute_t za; int err = 0;
int err;
err = 0; zap_attribute_t *za = kmem_alloc(sizeof (*za), KM_SLEEP);
for (zap_cursor_init(&zc, os, fromobj); for (zap_cursor_init(&zc, os, fromobj);
zap_cursor_retrieve(&zc, &za) == 0; zap_cursor_retrieve(&zc, za) == 0;
(void) zap_cursor_advance(&zc)) { (void) zap_cursor_advance(&zc)) {
uint64_t delta = 0; uint64_t delta = 0;
if (za.za_integer_length != 8 || za.za_num_integers != 1) { if (za->za_integer_length != 8 || za->za_num_integers != 1) {
err = SET_ERROR(EINVAL); err = SET_ERROR(EINVAL);
break; break;
} }
err = zap_lookup(os, intoobj, za.za_name, 8, 1, &delta); err = zap_lookup(os, intoobj, za->za_name, 8, 1, &delta);
if (err != 0 && err != ENOENT) if (err != 0 && err != ENOENT)
break; break;
delta += za.za_first_integer; delta += za->za_first_integer;
err = zap_update(os, intoobj, za.za_name, 8, 1, &delta, tx); err = zap_update(os, intoobj, za->za_name, 8, 1, &delta, tx);
if (err) if (err != 0)
break; break;
} }
zap_cursor_fini(&zc); zap_cursor_fini(&zc);
kmem_free(za, sizeof (*za));
return (err); return (err);
} }
@ -1177,12 +1150,11 @@ zap_increment(objset_t *os, uint64_t obj, const char *name, int64_t delta,
dmu_tx_t *tx) dmu_tx_t *tx)
{ {
uint64_t value = 0; uint64_t value = 0;
int err;
if (delta == 0) if (delta == 0)
return (0); return (0);
err = zap_lookup(os, obj, name, 8, 1, &value); int err = zap_lookup(os, obj, name, 8, 1, &value);
if (err != 0 && err != ENOENT) if (err != 0 && err != ENOENT)
return (err); return (err);
value += delta; value += delta;
@ -1286,7 +1258,6 @@ again:
static void static void
zap_stats_ptrtbl(zap_t *zap, uint64_t *tbl, int len, zap_stats_t *zs) zap_stats_ptrtbl(zap_t *zap, uint64_t *tbl, int len, zap_stats_t *zs)
{ {
int i, err;
uint64_t lastblk = 0; uint64_t lastblk = 0;
/* /*
@ -1294,14 +1265,14 @@ zap_stats_ptrtbl(zap_t *zap, uint64_t *tbl, int len, zap_stats_t *zs)
* can hold, then it'll be accounted for more than once, since * can hold, then it'll be accounted for more than once, since
* we won't have lastblk. * we won't have lastblk.
*/ */
for (i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
zap_leaf_t *l; zap_leaf_t *l;
if (tbl[i] == lastblk) if (tbl[i] == lastblk)
continue; continue;
lastblk = tbl[i]; lastblk = tbl[i];
err = zap_get_leaf_byblk(zap, tbl[i], NULL, RW_READER, &l); int err = zap_get_leaf_byblk(zap, tbl[i], NULL, RW_READER, &l);
if (err == 0) { if (err == 0) {
zap_leaf_stats(zap, l, zs); zap_leaf_stats(zap, l, zs);
zap_put_leaf(l); zap_put_leaf(l);
@ -1341,14 +1312,12 @@ fzap_get_stats(zap_t *zap, zap_stats_t *zs)
zap_stats_ptrtbl(zap, &ZAP_EMBEDDED_PTRTBL_ENT(zap, 0), zap_stats_ptrtbl(zap, &ZAP_EMBEDDED_PTRTBL_ENT(zap, 0),
1 << ZAP_EMBEDDED_PTRTBL_SHIFT(zap), zs); 1 << ZAP_EMBEDDED_PTRTBL_SHIFT(zap), zs);
} else { } else {
int b;
dmu_prefetch(zap->zap_objset, zap->zap_object, 0, dmu_prefetch(zap->zap_objset, zap->zap_object, 0,
zap_f_phys(zap)->zap_ptrtbl.zt_blk << bs, zap_f_phys(zap)->zap_ptrtbl.zt_blk << bs,
zap_f_phys(zap)->zap_ptrtbl.zt_numblks << bs, zap_f_phys(zap)->zap_ptrtbl.zt_numblks << bs,
ZIO_PRIORITY_SYNC_READ); ZIO_PRIORITY_SYNC_READ);
for (b = 0; b < zap_f_phys(zap)->zap_ptrtbl.zt_numblks; for (int b = 0; b < zap_f_phys(zap)->zap_ptrtbl.zt_numblks;
b++) { b++) {
dmu_buf_t *db; dmu_buf_t *db;
int err; int err;

View File

@ -21,7 +21,7 @@
/* /*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2015 by Delphix. All rights reserved. * Copyright (c) 2013, 2016 by Delphix. All rights reserved.
* Copyright 2017 Nexenta Systems, Inc. * Copyright 2017 Nexenta Systems, Inc.
*/ */
@ -109,7 +109,6 @@ ldv(int len, const void *addr)
void void
zap_leaf_byteswap(zap_leaf_phys_t *buf, int size) zap_leaf_byteswap(zap_leaf_phys_t *buf, int size)
{ {
int i;
zap_leaf_t l; zap_leaf_t l;
dmu_buf_t l_dbuf; dmu_buf_t l_dbuf;
@ -125,10 +124,10 @@ zap_leaf_byteswap(zap_leaf_phys_t *buf, int size)
buf->l_hdr.lh_prefix_len = BSWAP_16(buf->l_hdr.lh_prefix_len); buf->l_hdr.lh_prefix_len = BSWAP_16(buf->l_hdr.lh_prefix_len);
buf->l_hdr.lh_freelist = BSWAP_16(buf->l_hdr.lh_freelist); buf->l_hdr.lh_freelist = BSWAP_16(buf->l_hdr.lh_freelist);
for (i = 0; i < ZAP_LEAF_HASH_NUMENTRIES(&l); i++) for (int i = 0; i < ZAP_LEAF_HASH_NUMENTRIES(&l); i++)
buf->l_hash[i] = BSWAP_16(buf->l_hash[i]); buf->l_hash[i] = BSWAP_16(buf->l_hash[i]);
for (i = 0; i < ZAP_LEAF_NUMCHUNKS(&l); i++) { for (int i = 0; i < ZAP_LEAF_NUMCHUNKS(&l); i++) {
zap_leaf_chunk_t *lc = &ZAP_LEAF_CHUNK(&l, i); zap_leaf_chunk_t *lc = &ZAP_LEAF_CHUNK(&l, i);
struct zap_leaf_entry *le; struct zap_leaf_entry *le;
@ -165,14 +164,12 @@ zap_leaf_byteswap(zap_leaf_phys_t *buf, int size)
void void
zap_leaf_init(zap_leaf_t *l, boolean_t sort) zap_leaf_init(zap_leaf_t *l, boolean_t sort)
{ {
int i;
l->l_bs = highbit64(l->l_dbuf->db_size) - 1; l->l_bs = highbit64(l->l_dbuf->db_size) - 1;
zap_memset(&zap_leaf_phys(l)->l_hdr, 0, zap_memset(&zap_leaf_phys(l)->l_hdr, 0,
sizeof (struct zap_leaf_header)); sizeof (struct zap_leaf_header));
zap_memset(zap_leaf_phys(l)->l_hash, CHAIN_END, zap_memset(zap_leaf_phys(l)->l_hash, CHAIN_END,
2*ZAP_LEAF_HASH_NUMENTRIES(l)); 2*ZAP_LEAF_HASH_NUMENTRIES(l));
for (i = 0; i < ZAP_LEAF_NUMCHUNKS(l); i++) { for (int i = 0; i < ZAP_LEAF_NUMCHUNKS(l); i++) {
ZAP_LEAF_CHUNK(l, i).l_free.lf_type = ZAP_CHUNK_FREE; ZAP_LEAF_CHUNK(l, i).l_free.lf_type = ZAP_CHUNK_FREE;
ZAP_LEAF_CHUNK(l, i).l_free.lf_next = i+1; ZAP_LEAF_CHUNK(l, i).l_free.lf_next = i+1;
} }
@ -191,11 +188,9 @@ zap_leaf_init(zap_leaf_t *l, boolean_t sort)
static uint16_t static uint16_t
zap_leaf_chunk_alloc(zap_leaf_t *l) zap_leaf_chunk_alloc(zap_leaf_t *l)
{ {
int chunk;
ASSERT(zap_leaf_phys(l)->l_hdr.lh_nfree > 0); ASSERT(zap_leaf_phys(l)->l_hdr.lh_nfree > 0);
chunk = zap_leaf_phys(l)->l_hdr.lh_freelist; int chunk = zap_leaf_phys(l)->l_hdr.lh_freelist;
ASSERT3U(chunk, <, ZAP_LEAF_NUMCHUNKS(l)); ASSERT3U(chunk, <, ZAP_LEAF_NUMCHUNKS(l));
ASSERT3U(ZAP_LEAF_CHUNK(l, chunk).l_free.lf_type, ==, ZAP_CHUNK_FREE); ASSERT3U(ZAP_LEAF_CHUNK(l, chunk).l_free.lf_type, ==, ZAP_CHUNK_FREE);
@ -235,7 +230,7 @@ zap_leaf_array_create(zap_leaf_t *l, const char *buf,
uint16_t *chunkp = &chunk_head; uint16_t *chunkp = &chunk_head;
int byten = 0; int byten = 0;
uint64_t value = 0; uint64_t value = 0;
int shift = (integer_size-1)*8; int shift = (integer_size - 1) * 8;
int len = num_integers; int len = num_integers;
ASSERT3U(num_integers * integer_size, <, MAX_ARRAY_BYTES); ASSERT3U(num_integers * integer_size, <, MAX_ARRAY_BYTES);
@ -243,10 +238,9 @@ zap_leaf_array_create(zap_leaf_t *l, const char *buf,
while (len > 0) { while (len > 0) {
uint16_t chunk = zap_leaf_chunk_alloc(l); uint16_t chunk = zap_leaf_chunk_alloc(l);
struct zap_leaf_array *la = &ZAP_LEAF_CHUNK(l, chunk).l_array; struct zap_leaf_array *la = &ZAP_LEAF_CHUNK(l, chunk).l_array;
int i;
la->la_type = ZAP_CHUNK_ARRAY; la->la_type = ZAP_CHUNK_ARRAY;
for (i = 0; i < ZAP_LEAF_ARRAY_BYTES; i++) { for (int i = 0; i < ZAP_LEAF_ARRAY_BYTES; i++) {
if (byten == 0) if (byten == 0)
value = ldv(integer_size, buf); value = ldv(integer_size, buf);
la->la_array[i] = value >> shift; la->la_array[i] = value >> shift;
@ -324,10 +318,9 @@ zap_leaf_array_read(zap_leaf_t *l, uint16_t chunk,
while (len > 0) { while (len > 0) {
struct zap_leaf_array *la = &ZAP_LEAF_CHUNK(l, chunk).l_array; struct zap_leaf_array *la = &ZAP_LEAF_CHUNK(l, chunk).l_array;
int i;
ASSERT3U(chunk, <, ZAP_LEAF_NUMCHUNKS(l)); ASSERT3U(chunk, <, ZAP_LEAF_NUMCHUNKS(l));
for (i = 0; i < ZAP_LEAF_ARRAY_BYTES && len > 0; i++) { for (int i = 0; i < ZAP_LEAF_ARRAY_BYTES && len > 0; i++) {
value = (value << 8) | la->la_array[i]; value = (value << 8) | la->la_array[i];
byten++; byten++;
if (byten == array_int_len) { if (byten == array_int_len) {
@ -350,16 +343,13 @@ zap_leaf_array_match(zap_leaf_t *l, zap_name_t *zn,
int bseen = 0; int bseen = 0;
if (zap_getflags(zn->zn_zap) & ZAP_FLAG_UINT64_KEY) { if (zap_getflags(zn->zn_zap) & ZAP_FLAG_UINT64_KEY) {
uint64_t *thiskey; uint64_t *thiskey =
boolean_t match; kmem_alloc(array_numints * sizeof (*thiskey), KM_SLEEP);
ASSERT(zn->zn_key_intlen == sizeof (*thiskey)); ASSERT(zn->zn_key_intlen == sizeof (*thiskey));
thiskey = kmem_alloc(array_numints * sizeof (*thiskey),
KM_SLEEP);
zap_leaf_array_read(l, chunk, sizeof (*thiskey), array_numints, zap_leaf_array_read(l, chunk, sizeof (*thiskey), array_numints,
sizeof (*thiskey), array_numints, thiskey); sizeof (*thiskey), array_numints, thiskey);
match = bcmp(thiskey, zn->zn_key_orig, boolean_t match = bcmp(thiskey, zn->zn_key_orig,
array_numints * sizeof (*thiskey)) == 0; array_numints * sizeof (*thiskey)) == 0;
kmem_free(thiskey, array_numints * sizeof (*thiskey)); kmem_free(thiskey, array_numints * sizeof (*thiskey));
return (match); return (match);
@ -368,11 +358,10 @@ zap_leaf_array_match(zap_leaf_t *l, zap_name_t *zn,
ASSERT(zn->zn_key_intlen == 1); ASSERT(zn->zn_key_intlen == 1);
if (zn->zn_matchtype & MT_NORMALIZE) { if (zn->zn_matchtype & MT_NORMALIZE) {
char *thisname = kmem_alloc(array_numints, KM_SLEEP); char *thisname = kmem_alloc(array_numints, KM_SLEEP);
boolean_t match;
zap_leaf_array_read(l, chunk, sizeof (char), array_numints, zap_leaf_array_read(l, chunk, sizeof (char), array_numints,
sizeof (char), array_numints, thisname); sizeof (char), array_numints, thisname);
match = zap_match(zn, thisname); boolean_t match = zap_match(zn, thisname);
kmem_free(thisname, array_numints); kmem_free(thisname, array_numints);
return (match); return (match);
} }
@ -403,12 +392,11 @@ zap_leaf_array_match(zap_leaf_t *l, zap_name_t *zn,
int int
zap_leaf_lookup(zap_leaf_t *l, zap_name_t *zn, zap_entry_handle_t *zeh) zap_leaf_lookup(zap_leaf_t *l, zap_name_t *zn, zap_entry_handle_t *zeh)
{ {
uint16_t *chunkp;
struct zap_leaf_entry *le; struct zap_leaf_entry *le;
ASSERT3U(zap_leaf_phys(l)->l_hdr.lh_magic, ==, ZAP_LEAF_MAGIC); ASSERT3U(zap_leaf_phys(l)->l_hdr.lh_magic, ==, ZAP_LEAF_MAGIC);
for (chunkp = LEAF_HASH_ENTPTR(l, zn->zn_hash); for (uint16_t *chunkp = LEAF_HASH_ENTPTR(l, zn->zn_hash);
*chunkp != CHAIN_END; chunkp = &le->le_next) { *chunkp != CHAIN_END; chunkp = &le->le_next) {
uint16_t chunk = *chunkp; uint16_t chunk = *chunkp;
le = ZAP_LEAF_ENTRY(l, chunk); le = ZAP_LEAF_ENTRY(l, chunk);
@ -449,17 +437,15 @@ int
zap_leaf_lookup_closest(zap_leaf_t *l, zap_leaf_lookup_closest(zap_leaf_t *l,
uint64_t h, uint32_t cd, zap_entry_handle_t *zeh) uint64_t h, uint32_t cd, zap_entry_handle_t *zeh)
{ {
uint16_t chunk;
uint64_t besth = -1ULL; uint64_t besth = -1ULL;
uint32_t bestcd = -1U; uint32_t bestcd = -1U;
uint16_t bestlh = ZAP_LEAF_HASH_NUMENTRIES(l)-1; uint16_t bestlh = ZAP_LEAF_HASH_NUMENTRIES(l)-1;
uint16_t lh;
struct zap_leaf_entry *le; struct zap_leaf_entry *le;
ASSERT3U(zap_leaf_phys(l)->l_hdr.lh_magic, ==, ZAP_LEAF_MAGIC); ASSERT3U(zap_leaf_phys(l)->l_hdr.lh_magic, ==, ZAP_LEAF_MAGIC);
for (lh = LEAF_HASH(l, h); lh <= bestlh; lh++) { for (uint16_t lh = LEAF_HASH(l, h); lh <= bestlh; lh++) {
for (chunk = zap_leaf_phys(l)->l_hash[lh]; for (uint16_t chunk = zap_leaf_phys(l)->l_hash[lh];
chunk != CHAIN_END; chunk = le->le_next) { chunk != CHAIN_END; chunk = le->le_next) {
le = ZAP_LEAF_ENTRY(l, chunk); le = ZAP_LEAF_ENTRY(l, chunk);
@ -532,11 +518,10 @@ int
zap_entry_update(zap_entry_handle_t *zeh, zap_entry_update(zap_entry_handle_t *zeh,
uint8_t integer_size, uint64_t num_integers, const void *buf) uint8_t integer_size, uint64_t num_integers, const void *buf)
{ {
int delta_chunks;
zap_leaf_t *l = zeh->zeh_leaf; zap_leaf_t *l = zeh->zeh_leaf;
struct zap_leaf_entry *le = ZAP_LEAF_ENTRY(l, *zeh->zeh_chunkp); struct zap_leaf_entry *le = ZAP_LEAF_ENTRY(l, *zeh->zeh_chunkp);
delta_chunks = ZAP_LEAF_ARRAY_NCHUNKS(num_integers * integer_size) - int delta_chunks = ZAP_LEAF_ARRAY_NCHUNKS(num_integers * integer_size) -
ZAP_LEAF_ARRAY_NCHUNKS(le->le_value_numints * le->le_value_intlen); ZAP_LEAF_ARRAY_NCHUNKS(le->le_value_numints * le->le_value_intlen);
if ((int)zap_leaf_phys(l)->l_hdr.lh_nfree < delta_chunks) if ((int)zap_leaf_phys(l)->l_hdr.lh_nfree < delta_chunks)
@ -553,14 +538,12 @@ zap_entry_update(zap_entry_handle_t *zeh,
void void
zap_entry_remove(zap_entry_handle_t *zeh) zap_entry_remove(zap_entry_handle_t *zeh)
{ {
uint16_t entry_chunk;
struct zap_leaf_entry *le;
zap_leaf_t *l = zeh->zeh_leaf; zap_leaf_t *l = zeh->zeh_leaf;
ASSERT3P(zeh->zeh_chunkp, !=, &zeh->zeh_fakechunk); ASSERT3P(zeh->zeh_chunkp, !=, &zeh->zeh_fakechunk);
entry_chunk = *zeh->zeh_chunkp; uint16_t entry_chunk = *zeh->zeh_chunkp;
le = ZAP_LEAF_ENTRY(l, entry_chunk); struct zap_leaf_entry *le = ZAP_LEAF_ENTRY(l, entry_chunk);
ASSERT3U(le->le_type, ==, ZAP_CHUNK_ENTRY); ASSERT3U(le->le_type, ==, ZAP_CHUNK_ENTRY);
zap_leaf_array_free(l, &le->le_name_chunk); zap_leaf_array_free(l, &le->le_name_chunk);
@ -578,15 +561,12 @@ zap_entry_create(zap_leaf_t *l, zap_name_t *zn, uint32_t cd,
zap_entry_handle_t *zeh) zap_entry_handle_t *zeh)
{ {
uint16_t chunk; uint16_t chunk;
uint16_t *chunkp;
struct zap_leaf_entry *le; struct zap_leaf_entry *le;
uint64_t valuelen;
int numchunks;
uint64_t h = zn->zn_hash; uint64_t h = zn->zn_hash;
valuelen = integer_size * num_integers; uint64_t valuelen = integer_size * num_integers;
numchunks = 1 + ZAP_LEAF_ARRAY_NCHUNKS(zn->zn_key_orig_numints * int numchunks = 1 + ZAP_LEAF_ARRAY_NCHUNKS(zn->zn_key_orig_numints *
zn->zn_key_intlen) + ZAP_LEAF_ARRAY_NCHUNKS(valuelen); zn->zn_key_intlen) + ZAP_LEAF_ARRAY_NCHUNKS(valuelen);
if (numchunks > ZAP_LEAF_NUMCHUNKS(l)) if (numchunks > ZAP_LEAF_NUMCHUNKS(l))
return (SET_ERROR(E2BIG)); return (SET_ERROR(E2BIG));
@ -648,7 +628,7 @@ zap_entry_create(zap_leaf_t *l, zap_name_t *zn, uint32_t cd,
/* link it into the hash chain */ /* link it into the hash chain */
/* XXX if we did the search above, we could just use that */ /* XXX if we did the search above, we could just use that */
chunkp = zap_leaf_rehash_entry(l, chunk); uint16_t *chunkp = zap_leaf_rehash_entry(l, chunk);
zap_leaf_phys(l)->l_hdr.lh_nentries++; zap_leaf_phys(l)->l_hdr.lh_nentries++;
@ -676,14 +656,13 @@ boolean_t
zap_entry_normalization_conflict(zap_entry_handle_t *zeh, zap_name_t *zn, zap_entry_normalization_conflict(zap_entry_handle_t *zeh, zap_name_t *zn,
const char *name, zap_t *zap) const char *name, zap_t *zap)
{ {
uint64_t chunk;
struct zap_leaf_entry *le; struct zap_leaf_entry *le;
boolean_t allocdzn = B_FALSE; boolean_t allocdzn = B_FALSE;
if (zap->zap_normflags == 0) if (zap->zap_normflags == 0)
return (B_FALSE); return (B_FALSE);
for (chunk = *LEAF_HASH_ENTPTR(zeh->zeh_leaf, zeh->zeh_hash); for (uint16_t chunk = *LEAF_HASH_ENTPTR(zeh->zeh_leaf, zeh->zeh_hash);
chunk != CHAIN_END; chunk = le->le_next) { chunk != CHAIN_END; chunk = le->le_next) {
le = ZAP_LEAF_ENTRY(zeh->zeh_leaf, chunk); le = ZAP_LEAF_ENTRY(zeh->zeh_leaf, chunk);
if (le->le_hash != zeh->zeh_hash) if (le->le_hash != zeh->zeh_hash)
@ -766,14 +745,11 @@ zap_leaf_transfer_array(zap_leaf_t *l, uint16_t chunk, zap_leaf_t *nl)
static void static void
zap_leaf_transfer_entry(zap_leaf_t *l, int entry, zap_leaf_t *nl) zap_leaf_transfer_entry(zap_leaf_t *l, int entry, zap_leaf_t *nl)
{ {
struct zap_leaf_entry *le, *nle; struct zap_leaf_entry *le = ZAP_LEAF_ENTRY(l, entry);
uint16_t chunk;
le = ZAP_LEAF_ENTRY(l, entry);
ASSERT3U(le->le_type, ==, ZAP_CHUNK_ENTRY); ASSERT3U(le->le_type, ==, ZAP_CHUNK_ENTRY);
chunk = zap_leaf_chunk_alloc(nl); uint16_t chunk = zap_leaf_chunk_alloc(nl);
nle = ZAP_LEAF_ENTRY(nl, chunk); struct zap_leaf_entry *nle = ZAP_LEAF_ENTRY(nl, chunk);
*nle = *le; /* structure assignment */ *nle = *le; /* structure assignment */
(void) zap_leaf_rehash_entry(nl, chunk); (void) zap_leaf_rehash_entry(nl, chunk);
@ -794,7 +770,6 @@ zap_leaf_transfer_entry(zap_leaf_t *l, int entry, zap_leaf_t *nl)
void void
zap_leaf_split(zap_leaf_t *l, zap_leaf_t *nl, boolean_t sort) zap_leaf_split(zap_leaf_t *l, zap_leaf_t *nl, boolean_t sort)
{ {
int i;
int bit = 64 - 1 - zap_leaf_phys(l)->l_hdr.lh_prefix_len; int bit = 64 - 1 - zap_leaf_phys(l)->l_hdr.lh_prefix_len;
/* set new prefix and prefix_len */ /* set new prefix and prefix_len */
@ -821,7 +796,7 @@ zap_leaf_split(zap_leaf_t *l, zap_leaf_t *nl, boolean_t sort)
* but this accesses memory more sequentially, and when we're * but this accesses memory more sequentially, and when we're
* called, the block is usually pretty full. * called, the block is usually pretty full.
*/ */
for (i = 0; i < ZAP_LEAF_NUMCHUNKS(l); i++) { for (int i = 0; i < ZAP_LEAF_NUMCHUNKS(l); i++) {
struct zap_leaf_entry *le = ZAP_LEAF_ENTRY(l, i); struct zap_leaf_entry *le = ZAP_LEAF_ENTRY(l, i);
if (le->le_type != ZAP_CHUNK_ENTRY) if (le->le_type != ZAP_CHUNK_ENTRY)
continue; continue;
@ -836,9 +811,7 @@ zap_leaf_split(zap_leaf_t *l, zap_leaf_t *nl, boolean_t sort)
void void
zap_leaf_stats(zap_t *zap, zap_leaf_t *l, zap_stats_t *zs) zap_leaf_stats(zap_t *zap, zap_leaf_t *l, zap_stats_t *zs)
{ {
int i, n; int n = zap_f_phys(zap)->zap_ptrtbl.zt_shift -
n = zap_f_phys(zap)->zap_ptrtbl.zt_shift -
zap_leaf_phys(l)->l_hdr.lh_prefix_len; zap_leaf_phys(l)->l_hdr.lh_prefix_len;
n = MIN(n, ZAP_HISTOGRAM_SIZE-1); n = MIN(n, ZAP_HISTOGRAM_SIZE-1);
zs->zs_leafs_with_2n_pointers[n]++; zs->zs_leafs_with_2n_pointers[n]++;
@ -854,7 +827,7 @@ zap_leaf_stats(zap_t *zap, zap_leaf_t *l, zap_stats_t *zs)
n = MIN(n, ZAP_HISTOGRAM_SIZE-1); n = MIN(n, ZAP_HISTOGRAM_SIZE-1);
zs->zs_blocks_n_tenths_full[n]++; zs->zs_blocks_n_tenths_full[n]++;
for (i = 0; i < ZAP_LEAF_HASH_NUMENTRIES(l); i++) { for (int i = 0; i < ZAP_LEAF_HASH_NUMENTRIES(l); i++) {
int nentries = 0; int nentries = 0;
int chunk = zap_leaf_phys(l)->l_hash[i]; int chunk = zap_leaf_phys(l)->l_hash[i];

View File

@ -88,22 +88,20 @@ zap_hash(zap_name_t *zn)
ASSERT(zfs_crc64_table[128] == ZFS_CRC64_POLY); ASSERT(zfs_crc64_table[128] == ZFS_CRC64_POLY);
if (zap_getflags(zap) & ZAP_FLAG_UINT64_KEY) { if (zap_getflags(zap) & ZAP_FLAG_UINT64_KEY) {
int i;
const uint64_t *wp = zn->zn_key_norm; const uint64_t *wp = zn->zn_key_norm;
ASSERT(zn->zn_key_intlen == 8); ASSERT(zn->zn_key_intlen == 8);
for (i = 0; i < zn->zn_key_norm_numints; wp++, i++) { for (int i = 0; i < zn->zn_key_norm_numints;
int j; wp++, i++) {
uint64_t word = *wp; uint64_t word = *wp;
for (j = 0; j < zn->zn_key_intlen; j++) { for (int j = 0; j < zn->zn_key_intlen; j++) {
h = (h >> 8) ^ h = (h >> 8) ^
zfs_crc64_table[(h ^ word) & 0xFF]; zfs_crc64_table[(h ^ word) & 0xFF];
word >>= NBBY; word >>= NBBY;
} }
} }
} else { } else {
int i, len;
const uint8_t *cp = zn->zn_key_norm; const uint8_t *cp = zn->zn_key_norm;
/* /*
@ -113,10 +111,10 @@ zap_hash(zap_name_t *zn)
* zn_key_*_numints includes the terminating * zn_key_*_numints includes the terminating
* null for non-binary keys.) * null for non-binary keys.)
*/ */
len = zn->zn_key_norm_numints - 1; int len = zn->zn_key_norm_numints - 1;
ASSERT(zn->zn_key_intlen == 1); ASSERT(zn->zn_key_intlen == 1);
for (i = 0; i < len; cp++, i++) { for (int i = 0; i < len; cp++, i++) {
h = (h >> 8) ^ h = (h >> 8) ^
zfs_crc64_table[(h ^ *cp) & 0xFF]; zfs_crc64_table[(h ^ *cp) & 0xFF];
} }
@ -136,15 +134,12 @@ zap_hash(zap_name_t *zn)
static int static int
zap_normalize(zap_t *zap, const char *name, char *namenorm, int normflags) zap_normalize(zap_t *zap, const char *name, char *namenorm, int normflags)
{ {
size_t inlen, outlen;
int err;
ASSERT(!(zap_getflags(zap) & ZAP_FLAG_UINT64_KEY)); ASSERT(!(zap_getflags(zap) & ZAP_FLAG_UINT64_KEY));
inlen = strlen(name) + 1; size_t inlen = strlen(name) + 1;
outlen = ZAP_MAXNAMELEN; size_t outlen = ZAP_MAXNAMELEN;
err = 0; int err = 0;
(void) u8_textprep_str((char *)name, &inlen, namenorm, &outlen, (void) u8_textprep_str((char *)name, &inlen, namenorm, &outlen,
normflags | U8_TEXTPREP_IGNORE_NULL | U8_TEXTPREP_IGNORE_INVALID, normflags | U8_TEXTPREP_IGNORE_NULL | U8_TEXTPREP_IGNORE_INVALID,
U8_UNICODE_LATEST, &err); U8_UNICODE_LATEST, &err);
@ -254,12 +249,11 @@ zap_name_alloc_uint64(zap_t *zap, const uint64_t *key, int numints)
static void static void
mzap_byteswap(mzap_phys_t *buf, size_t size) mzap_byteswap(mzap_phys_t *buf, size_t size)
{ {
int i, max;
buf->mz_block_type = BSWAP_64(buf->mz_block_type); buf->mz_block_type = BSWAP_64(buf->mz_block_type);
buf->mz_salt = BSWAP_64(buf->mz_salt); buf->mz_salt = BSWAP_64(buf->mz_salt);
buf->mz_normflags = BSWAP_64(buf->mz_normflags); buf->mz_normflags = BSWAP_64(buf->mz_normflags);
max = (size / MZAP_ENT_LEN) - 1; int max = (size / MZAP_ENT_LEN) - 1;
for (i = 0; i < max; i++) { for (int i = 0; i < max; i++) {
buf->mz_chunk[i].mze_value = buf->mz_chunk[i].mze_value =
BSWAP_64(buf->mz_chunk[i].mze_value); BSWAP_64(buf->mz_chunk[i].mze_value);
buf->mz_chunk[i].mze_cd = buf->mz_chunk[i].mze_cd =
@ -270,9 +264,7 @@ mzap_byteswap(mzap_phys_t *buf, size_t size)
void void
zap_byteswap(void *buf, size_t size) zap_byteswap(void *buf, size_t size)
{ {
uint64_t block_type; uint64_t block_type = *(uint64_t *)buf;
block_type = *(uint64_t *)buf;
if (block_type == ZBT_MICRO || block_type == BSWAP_64(ZBT_MICRO)) { if (block_type == ZBT_MICRO || block_type == BSWAP_64(ZBT_MICRO)) {
/* ASSERT(magic == ZAP_LEAF_MAGIC); */ /* ASSERT(magic == ZAP_LEAF_MAGIC); */
@ -298,12 +290,10 @@ mze_compare(const void *arg1, const void *arg2)
static void static void
mze_insert(zap_t *zap, int chunkid, uint64_t hash) mze_insert(zap_t *zap, int chunkid, uint64_t hash)
{ {
mzap_ent_t *mze;
ASSERT(zap->zap_ismicro); ASSERT(zap->zap_ismicro);
ASSERT(RW_WRITE_HELD(&zap->zap_rwlock)); ASSERT(RW_WRITE_HELD(&zap->zap_rwlock));
mze = kmem_alloc(sizeof (mzap_ent_t), KM_SLEEP); mzap_ent_t *mze = kmem_alloc(sizeof (mzap_ent_t), KM_SLEEP);
mze->mze_chunkid = chunkid; mze->mze_chunkid = chunkid;
mze->mze_hash = hash; mze->mze_hash = hash;
mze->mze_cd = MZE_PHYS(zap, mze)->mze_cd; mze->mze_cd = MZE_PHYS(zap, mze)->mze_cd;
@ -341,10 +331,8 @@ static uint32_t
mze_find_unused_cd(zap_t *zap, uint64_t hash) mze_find_unused_cd(zap_t *zap, uint64_t hash)
{ {
mzap_ent_t mze_tofind; mzap_ent_t mze_tofind;
mzap_ent_t *mze;
avl_index_t idx; avl_index_t idx;
avl_tree_t *avl = &zap->zap_m.zap_avl; avl_tree_t *avl = &zap->zap_m.zap_avl;
uint32_t cd;
ASSERT(zap->zap_ismicro); ASSERT(zap->zap_ismicro);
ASSERT(RW_LOCK_HELD(&zap->zap_rwlock)); ASSERT(RW_LOCK_HELD(&zap->zap_rwlock));
@ -352,8 +340,8 @@ mze_find_unused_cd(zap_t *zap, uint64_t hash)
mze_tofind.mze_hash = hash; mze_tofind.mze_hash = hash;
mze_tofind.mze_cd = 0; mze_tofind.mze_cd = 0;
cd = 0; uint32_t cd = 0;
for (mze = avl_find(avl, &mze_tofind, &idx); for (mzap_ent_t *mze = avl_find(avl, &mze_tofind, &idx);
mze && mze->mze_hash == hash; mze = AVL_NEXT(avl, mze)) { mze && mze->mze_hash == hash; mze = AVL_NEXT(avl, mze)) {
if (mze->mze_cd != cd) if (mze->mze_cd != cd)
break; break;
@ -423,15 +411,13 @@ static zap_t *
mzap_open(objset_t *os, uint64_t obj, dmu_buf_t *db) mzap_open(objset_t *os, uint64_t obj, dmu_buf_t *db)
{ {
zap_t *winner; zap_t *winner;
zap_t *zap;
int i;
uint64_t *zap_hdr = (uint64_t *)db->db_data; uint64_t *zap_hdr = (uint64_t *)db->db_data;
uint64_t zap_block_type = zap_hdr[0]; uint64_t zap_block_type = zap_hdr[0];
uint64_t zap_magic = zap_hdr[1]; uint64_t zap_magic = zap_hdr[1];
ASSERT3U(MZAP_ENT_LEN, ==, sizeof (mzap_ent_phys_t)); ASSERT3U(MZAP_ENT_LEN, ==, sizeof (mzap_ent_phys_t));
zap = kmem_zalloc(sizeof (zap_t), KM_SLEEP); zap_t *zap = kmem_zalloc(sizeof (zap_t), KM_SLEEP);
rw_init(&zap->zap_rwlock, NULL, RW_DEFAULT, NULL); rw_init(&zap->zap_rwlock, NULL, RW_DEFAULT, NULL);
rw_enter(&zap->zap_rwlock, RW_WRITER); rw_enter(&zap->zap_rwlock, RW_WRITER);
zap->zap_objset = os; zap->zap_objset = os;
@ -468,7 +454,7 @@ mzap_open(objset_t *os, uint64_t obj, dmu_buf_t *db)
avl_create(&zap->zap_m.zap_avl, mze_compare, avl_create(&zap->zap_m.zap_avl, mze_compare,
sizeof (mzap_ent_t), offsetof(mzap_ent_t, mze_node)); sizeof (mzap_ent_t), offsetof(mzap_ent_t, mze_node));
for (i = 0; i < zap->zap_m.zap_num_chunks; i++) { for (int i = 0; i < zap->zap_m.zap_num_chunks; i++) {
mzap_ent_phys_t *mze = mzap_ent_phys_t *mze =
&zap_m_phys(zap)->mz_chunk[i]; &zap_m_phys(zap)->mz_chunk[i];
if (mze->mze_name[0]) { if (mze->mze_name[0]) {
@ -519,21 +505,18 @@ static int
zap_lockdir_impl(dmu_buf_t *db, void *tag, dmu_tx_t *tx, zap_lockdir_impl(dmu_buf_t *db, void *tag, dmu_tx_t *tx,
krw_t lti, boolean_t fatreader, boolean_t adding, zap_t **zapp) krw_t lti, boolean_t fatreader, boolean_t adding, zap_t **zapp)
{ {
dmu_object_info_t doi; ASSERT0(db->db_offset);
zap_t *zap;
krw_t lt;
objset_t *os = dmu_buf_get_objset(db); objset_t *os = dmu_buf_get_objset(db);
uint64_t obj = db->db_object; uint64_t obj = db->db_object;
dmu_object_info_t doi;
ASSERT0(db->db_offset);
*zapp = NULL; *zapp = NULL;
dmu_object_info_from_db(db, &doi); dmu_object_info_from_db(db, &doi);
if (DMU_OT_BYTESWAP(doi.doi_type) != DMU_BSWAP_ZAP) if (DMU_OT_BYTESWAP(doi.doi_type) != DMU_BSWAP_ZAP)
return (SET_ERROR(EINVAL)); return (SET_ERROR(EINVAL));
zap = dmu_buf_get_user(db); zap_t *zap = dmu_buf_get_user(db);
if (zap == NULL) { if (zap == NULL) {
zap = mzap_open(os, obj, db); zap = mzap_open(os, obj, db);
if (zap == NULL) { if (zap == NULL) {
@ -552,7 +535,7 @@ zap_lockdir_impl(dmu_buf_t *db, void *tag, dmu_tx_t *tx,
* can only be different if it was upgraded from micro to fat, * can only be different if it was upgraded from micro to fat,
* and micro wanted WRITER but fat only needs READER. * and micro wanted WRITER but fat only needs READER.
*/ */
lt = (!zap->zap_ismicro && fatreader) ? RW_READER : lti; krw_t lt = (!zap->zap_ismicro && fatreader) ? RW_READER : lti;
rw_enter(&zap->zap_rwlock, lt); rw_enter(&zap->zap_rwlock, lt);
if (lt != ((!zap->zap_ismicro && fatreader) ? RW_READER : lti)) { if (lt != ((!zap->zap_ismicro && fatreader) ? RW_READER : lti)) {
/* it was upgraded, now we only need reader */ /* it was upgraded, now we only need reader */
@ -598,9 +581,8 @@ zap_lockdir_by_dnode(dnode_t *dn, dmu_tx_t *tx,
krw_t lti, boolean_t fatreader, boolean_t adding, void *tag, zap_t **zapp) krw_t lti, boolean_t fatreader, boolean_t adding, void *tag, zap_t **zapp)
{ {
dmu_buf_t *db; dmu_buf_t *db;
int err;
err = dmu_buf_hold_by_dnode(dn, 0, tag, &db, DMU_READ_NO_PREFETCH); int err = dmu_buf_hold_by_dnode(dn, 0, tag, &db, DMU_READ_NO_PREFETCH);
if (err != 0) { if (err != 0) {
return (err); return (err);
} }
@ -616,9 +598,8 @@ zap_lockdir(objset_t *os, uint64_t obj, dmu_tx_t *tx,
krw_t lti, boolean_t fatreader, boolean_t adding, void *tag, zap_t **zapp) krw_t lti, boolean_t fatreader, boolean_t adding, void *tag, zap_t **zapp)
{ {
dmu_buf_t *db; dmu_buf_t *db;
int err;
err = dmu_buf_hold(os, obj, 0, tag, &db, DMU_READ_NO_PREFETCH); int err = dmu_buf_hold(os, obj, 0, tag, &db, DMU_READ_NO_PREFETCH);
if (err != 0) if (err != 0)
return (err); return (err);
err = zap_lockdir_impl(db, tag, tx, lti, fatreader, adding, zapp); err = zap_lockdir_impl(db, tag, tx, lti, fatreader, adding, zapp);
@ -637,22 +618,20 @@ zap_unlockdir(zap_t *zap, void *tag)
static int static int
mzap_upgrade(zap_t **zapp, void *tag, dmu_tx_t *tx, zap_flags_t flags) mzap_upgrade(zap_t **zapp, void *tag, dmu_tx_t *tx, zap_flags_t flags)
{ {
mzap_phys_t *mzp;
int i, sz, nchunks;
int err = 0; int err = 0;
zap_t *zap = *zapp; zap_t *zap = *zapp;
ASSERT(RW_WRITE_HELD(&zap->zap_rwlock)); ASSERT(RW_WRITE_HELD(&zap->zap_rwlock));
sz = zap->zap_dbuf->db_size; int sz = zap->zap_dbuf->db_size;
mzp = vmem_alloc(sz, KM_SLEEP); mzap_phys_t *mzp = vmem_alloc(sz, KM_SLEEP);
bcopy(zap->zap_dbuf->db_data, mzp, sz); bcopy(zap->zap_dbuf->db_data, mzp, sz);
nchunks = zap->zap_m.zap_num_chunks; int nchunks = zap->zap_m.zap_num_chunks;
if (!flags) { if (!flags) {
err = dmu_object_set_blocksize(zap->zap_objset, zap->zap_object, err = dmu_object_set_blocksize(zap->zap_objset, zap->zap_object,
1ULL << fzap_default_block_shift, 0, tx); 1ULL << fzap_default_block_shift, 0, tx);
if (err) { if (err != 0) {
vmem_free(mzp, sz); vmem_free(mzp, sz);
return (err); return (err);
} }
@ -665,14 +644,13 @@ mzap_upgrade(zap_t **zapp, void *tag, dmu_tx_t *tx, zap_flags_t flags)
fzap_upgrade(zap, tx, flags); fzap_upgrade(zap, tx, flags);
for (i = 0; i < nchunks; i++) { for (int i = 0; i < nchunks; i++) {
mzap_ent_phys_t *mze = &mzp->mz_chunk[i]; mzap_ent_phys_t *mze = &mzp->mz_chunk[i];
zap_name_t *zn;
if (mze->mze_name[0] == 0) if (mze->mze_name[0] == 0)
continue; continue;
dprintf("adding %s=%llu\n", dprintf("adding %s=%llu\n",
mze->mze_name, mze->mze_value); mze->mze_name, mze->mze_value);
zn = zap_name_alloc(zap, mze->mze_name, 0); zap_name_t *zn = zap_name_alloc(zap, mze->mze_name, 0);
/* If we fail here, we would end up losing entries */ /* If we fail here, we would end up losing entries */
VERIFY0(fzap_add_cd(zn, 8, 1, &mze->mze_value, mze->mze_cd, VERIFY0(fzap_add_cd(zn, 8, 1, &mze->mze_value, mze->mze_cd,
tag, tx)); tag, tx));
@ -706,7 +684,6 @@ mzap_create_impl(objset_t *os, uint64_t obj, int normflags, zap_flags_t flags,
dmu_tx_t *tx) dmu_tx_t *tx)
{ {
dmu_buf_t *db; dmu_buf_t *db;
mzap_phys_t *zp;
VERIFY0(dmu_buf_hold(os, obj, 0, FTAG, &db, DMU_READ_NO_PREFETCH)); VERIFY0(dmu_buf_hold(os, obj, 0, FTAG, &db, DMU_READ_NO_PREFETCH));
@ -719,7 +696,7 @@ mzap_create_impl(objset_t *os, uint64_t obj, int normflags, zap_flags_t flags,
#endif #endif
dmu_buf_will_dirty(db, tx); dmu_buf_will_dirty(db, tx);
zp = db->db_data; mzap_phys_t *zp = db->db_data;
zp->mz_block_type = ZBT_MICRO; zp->mz_block_type = ZBT_MICRO;
zp->mz_salt = ((uintptr_t)db ^ (uintptr_t)tx ^ (obj << 1)) | 1ULL; zp->mz_salt = ((uintptr_t)db ^ (uintptr_t)tx ^ (obj << 1)) | 1ULL;
zp->mz_normflags = normflags; zp->mz_normflags = normflags;
@ -730,7 +707,7 @@ mzap_create_impl(objset_t *os, uint64_t obj, int normflags, zap_flags_t flags,
/* Only fat zap supports flags; upgrade immediately. */ /* Only fat zap supports flags; upgrade immediately. */
VERIFY(0 == zap_lockdir(os, obj, tx, RW_WRITER, VERIFY(0 == zap_lockdir(os, obj, tx, RW_WRITER,
B_FALSE, B_FALSE, FTAG, &zap)); B_FALSE, B_FALSE, FTAG, &zap));
VERIFY3U(0, ==, mzap_upgrade(&zap, FTAG, tx, flags)); VERIFY0(mzap_upgrade(&zap, FTAG, tx, flags));
zap_unlockdir(zap, FTAG); zap_unlockdir(zap, FTAG);
} }
} }
@ -765,9 +742,7 @@ zap_create_claim_norm_dnsize(objset_t *os, uint64_t obj, int normflags,
dmu_object_type_t ot, dmu_object_type_t bonustype, int bonuslen, dmu_object_type_t ot, dmu_object_type_t bonustype, int bonuslen,
int dnodesize, dmu_tx_t *tx) int dnodesize, dmu_tx_t *tx)
{ {
int err; int err = dmu_object_claim_dnsize(os, obj, ot, 0, bonustype, bonuslen,
err = dmu_object_claim_dnsize(os, obj, ot, 0, bonustype, bonuslen,
dnodesize, tx); dnodesize, tx);
if (err != 0) if (err != 0)
return (err); return (err);
@ -869,10 +844,10 @@ int
zap_count(objset_t *os, uint64_t zapobj, uint64_t *count) zap_count(objset_t *os, uint64_t zapobj, uint64_t *count)
{ {
zap_t *zap; zap_t *zap;
int err;
err = zap_lockdir(os, zapobj, NULL, RW_READER, TRUE, FALSE, FTAG, &zap); int err =
if (err) zap_lockdir(os, zapobj, NULL, RW_READER, TRUE, FALSE, FTAG, &zap);
if (err != 0)
return (err); return (err);
if (!zap->zap_ismicro) { if (!zap->zap_ismicro) {
err = fzap_count(zap, count); err = fzap_count(zap, count);
@ -890,7 +865,6 @@ zap_count(objset_t *os, uint64_t zapobj, uint64_t *count)
static boolean_t static boolean_t
mzap_normalization_conflict(zap_t *zap, zap_name_t *zn, mzap_ent_t *mze) mzap_normalization_conflict(zap_t *zap, zap_name_t *zn, mzap_ent_t *mze)
{ {
mzap_ent_t *other;
int direction = AVL_BEFORE; int direction = AVL_BEFORE;
boolean_t allocdzn = B_FALSE; boolean_t allocdzn = B_FALSE;
@ -898,7 +872,7 @@ mzap_normalization_conflict(zap_t *zap, zap_name_t *zn, mzap_ent_t *mze)
return (B_FALSE); return (B_FALSE);
again: again:
for (other = avl_walk(&zap->zap_m.zap_avl, mze, direction); for (mzap_ent_t *other = avl_walk(&zap->zap_m.zap_avl, mze, direction);
other && other->mze_hash == mze->mze_hash; other && other->mze_hash == mze->mze_hash;
other = avl_walk(&zap->zap_m.zap_avl, other, direction)) { other = avl_walk(&zap->zap_m.zap_avl, other, direction)) {
@ -943,10 +917,8 @@ zap_lookup_impl(zap_t *zap, const char *name,
boolean_t *ncp) boolean_t *ncp)
{ {
int err = 0; int err = 0;
mzap_ent_t *mze;
zap_name_t *zn;
zn = zap_name_alloc(zap, name, mt); zap_name_t *zn = zap_name_alloc(zap, name, mt);
if (zn == NULL) if (zn == NULL)
return (SET_ERROR(ENOTSUP)); return (SET_ERROR(ENOTSUP));
@ -954,7 +926,7 @@ zap_lookup_impl(zap_t *zap, const char *name,
err = fzap_lookup(zn, integer_size, num_integers, buf, err = fzap_lookup(zn, integer_size, num_integers, buf,
realname, rn_len, ncp); realname, rn_len, ncp);
} else { } else {
mze = mze_find(zn); mzap_ent_t *mze = mze_find(zn);
if (mze == NULL) { if (mze == NULL) {
err = SET_ERROR(ENOENT); err = SET_ERROR(ENOENT);
} else { } else {
@ -985,9 +957,9 @@ zap_lookup_norm(objset_t *os, uint64_t zapobj, const char *name,
boolean_t *ncp) boolean_t *ncp)
{ {
zap_t *zap; zap_t *zap;
int err;
err = zap_lockdir(os, zapobj, NULL, RW_READER, TRUE, FALSE, FTAG, &zap); int err =
zap_lockdir(os, zapobj, NULL, RW_READER, TRUE, FALSE, FTAG, &zap);
if (err != 0) if (err != 0)
return (err); return (err);
err = zap_lookup_impl(zap, name, integer_size, err = zap_lookup_impl(zap, name, integer_size,
@ -1033,9 +1005,8 @@ zap_lookup_norm_by_dnode(dnode_t *dn, const char *name,
boolean_t *ncp) boolean_t *ncp)
{ {
zap_t *zap; zap_t *zap;
int err;
err = zap_lockdir_by_dnode(dn, NULL, RW_READER, TRUE, FALSE, int err = zap_lockdir_by_dnode(dn, NULL, RW_READER, TRUE, FALSE,
FTAG, &zap); FTAG, &zap);
if (err != 0) if (err != 0)
return (err); return (err);
@ -1050,13 +1021,12 @@ zap_prefetch_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
int key_numints) int key_numints)
{ {
zap_t *zap; zap_t *zap;
int err;
zap_name_t *zn;
err = zap_lockdir(os, zapobj, NULL, RW_READER, TRUE, FALSE, FTAG, &zap); int err =
if (err) zap_lockdir(os, zapobj, NULL, RW_READER, TRUE, FALSE, FTAG, &zap);
if (err != 0)
return (err); return (err);
zn = zap_name_alloc_uint64(zap, key, key_numints); zap_name_t *zn = zap_name_alloc_uint64(zap, key, key_numints);
if (zn == NULL) { if (zn == NULL) {
zap_unlockdir(zap, FTAG); zap_unlockdir(zap, FTAG);
return (SET_ERROR(ENOTSUP)); return (SET_ERROR(ENOTSUP));
@ -1073,13 +1043,12 @@ zap_lookup_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
int key_numints, uint64_t integer_size, uint64_t num_integers, void *buf) int key_numints, uint64_t integer_size, uint64_t num_integers, void *buf)
{ {
zap_t *zap; zap_t *zap;
int err;
zap_name_t *zn;
err = zap_lockdir(os, zapobj, NULL, RW_READER, TRUE, FALSE, FTAG, &zap); int err =
if (err) zap_lockdir(os, zapobj, NULL, RW_READER, TRUE, FALSE, FTAG, &zap);
if (err != 0)
return (err); return (err);
zn = zap_name_alloc_uint64(zap, key, key_numints); zap_name_t *zn = zap_name_alloc_uint64(zap, key, key_numints);
if (zn == NULL) { if (zn == NULL) {
zap_unlockdir(zap, FTAG); zap_unlockdir(zap, FTAG);
return (SET_ERROR(ENOTSUP)); return (SET_ERROR(ENOTSUP));
@ -1107,14 +1076,12 @@ zap_length(objset_t *os, uint64_t zapobj, const char *name,
uint64_t *integer_size, uint64_t *num_integers) uint64_t *integer_size, uint64_t *num_integers)
{ {
zap_t *zap; zap_t *zap;
int err;
mzap_ent_t *mze;
zap_name_t *zn;
err = zap_lockdir(os, zapobj, NULL, RW_READER, TRUE, FALSE, FTAG, &zap); int err =
if (err) zap_lockdir(os, zapobj, NULL, RW_READER, TRUE, FALSE, FTAG, &zap);
if (err != 0)
return (err); return (err);
zn = zap_name_alloc(zap, name, 0); zap_name_t *zn = zap_name_alloc(zap, name, 0);
if (zn == NULL) { if (zn == NULL) {
zap_unlockdir(zap, FTAG); zap_unlockdir(zap, FTAG);
return (SET_ERROR(ENOTSUP)); return (SET_ERROR(ENOTSUP));
@ -1122,7 +1089,7 @@ zap_length(objset_t *os, uint64_t zapobj, const char *name,
if (!zap->zap_ismicro) { if (!zap->zap_ismicro) {
err = fzap_length(zn, integer_size, num_integers); err = fzap_length(zn, integer_size, num_integers);
} else { } else {
mze = mze_find(zn); mzap_ent_t *mze = mze_find(zn);
if (mze == NULL) { if (mze == NULL) {
err = SET_ERROR(ENOENT); err = SET_ERROR(ENOENT);
} else { } else {
@ -1142,13 +1109,12 @@ zap_length_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
int key_numints, uint64_t *integer_size, uint64_t *num_integers) int key_numints, uint64_t *integer_size, uint64_t *num_integers)
{ {
zap_t *zap; zap_t *zap;
int err;
zap_name_t *zn;
err = zap_lockdir(os, zapobj, NULL, RW_READER, TRUE, FALSE, FTAG, &zap); int err =
if (err) zap_lockdir(os, zapobj, NULL, RW_READER, TRUE, FALSE, FTAG, &zap);
if (err != 0)
return (err); return (err);
zn = zap_name_alloc_uint64(zap, key, key_numints); zap_name_t *zn = zap_name_alloc_uint64(zap, key, key_numints);
if (zn == NULL) { if (zn == NULL) {
zap_unlockdir(zap, FTAG); zap_unlockdir(zap, FTAG);
return (SET_ERROR(ENOTSUP)); return (SET_ERROR(ENOTSUP));
@ -1162,27 +1128,24 @@ zap_length_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
static void static void
mzap_addent(zap_name_t *zn, uint64_t value) mzap_addent(zap_name_t *zn, uint64_t value)
{ {
int i;
zap_t *zap = zn->zn_zap; zap_t *zap = zn->zn_zap;
int start = zap->zap_m.zap_alloc_next; int start = zap->zap_m.zap_alloc_next;
uint32_t cd;
ASSERT(RW_WRITE_HELD(&zap->zap_rwlock)); ASSERT(RW_WRITE_HELD(&zap->zap_rwlock));
#ifdef ZFS_DEBUG #ifdef ZFS_DEBUG
for (i = 0; i < zap->zap_m.zap_num_chunks; i++) { for (int i = 0; i < zap->zap_m.zap_num_chunks; i++) {
ASSERTV(mzap_ent_phys_t *mze); mzap_ent_phys_t *mze = &zap_m_phys(zap)->mz_chunk[i];
ASSERT(mze = &zap_m_phys(zap)->mz_chunk[i]);
ASSERT(strcmp(zn->zn_key_orig, mze->mze_name) != 0); ASSERT(strcmp(zn->zn_key_orig, mze->mze_name) != 0);
} }
#endif #endif
cd = mze_find_unused_cd(zap, zn->zn_hash); uint32_t cd = mze_find_unused_cd(zap, zn->zn_hash);
/* given the limited size of the microzap, this can't happen */ /* given the limited size of the microzap, this can't happen */
ASSERT(cd < zap_maxcd(zap)); ASSERT(cd < zap_maxcd(zap));
again: again:
for (i = start; i < zap->zap_m.zap_num_chunks; i++) { for (int i = start; i < zap->zap_m.zap_num_chunks; i++) {
mzap_ent_phys_t *mze = &zap_m_phys(zap)->mz_chunk[i]; mzap_ent_phys_t *mze = &zap_m_phys(zap)->mz_chunk[i];
if (mze->mze_name[0] == 0) { if (mze->mze_name[0] == 0) {
mze->mze_value = value; mze->mze_value = value;
@ -1210,12 +1173,10 @@ zap_add_impl(zap_t *zap, const char *key,
int integer_size, uint64_t num_integers, int integer_size, uint64_t num_integers,
const void *val, dmu_tx_t *tx, void *tag) const void *val, dmu_tx_t *tx, void *tag)
{ {
int err = 0;
mzap_ent_t *mze;
const uint64_t *intval = val; const uint64_t *intval = val;
zap_name_t *zn; int err = 0;
zn = zap_name_alloc(zap, key, 0); zap_name_t *zn = zap_name_alloc(zap, key, 0);
if (zn == NULL) { if (zn == NULL) {
zap_unlockdir(zap, tag); zap_unlockdir(zap, tag);
return (SET_ERROR(ENOTSUP)); return (SET_ERROR(ENOTSUP));
@ -1233,8 +1194,7 @@ zap_add_impl(zap_t *zap, const char *key,
} }
zap = zn->zn_zap; /* fzap_add() may change zap */ zap = zn->zn_zap; /* fzap_add() may change zap */
} else { } else {
mze = mze_find(zn); if (mze_find(zn) != NULL) {
if (mze != NULL) {
err = SET_ERROR(EEXIST); err = SET_ERROR(EEXIST);
} else { } else {
mzap_addent(zn, *intval); mzap_addent(zn, *intval);
@ -1285,13 +1245,12 @@ zap_add_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
const void *val, dmu_tx_t *tx) const void *val, dmu_tx_t *tx)
{ {
zap_t *zap; zap_t *zap;
int err;
zap_name_t *zn;
err = zap_lockdir(os, zapobj, tx, RW_WRITER, TRUE, TRUE, FTAG, &zap); int err =
if (err) zap_lockdir(os, zapobj, tx, RW_WRITER, TRUE, TRUE, FTAG, &zap);
if (err != 0)
return (err); return (err);
zn = zap_name_alloc_uint64(zap, key, key_numints); zap_name_t *zn = zap_name_alloc_uint64(zap, key, key_numints);
if (zn == NULL) { if (zn == NULL) {
zap_unlockdir(zap, FTAG); zap_unlockdir(zap, FTAG);
return (SET_ERROR(ENOTSUP)); return (SET_ERROR(ENOTSUP));
@ -1309,13 +1268,10 @@ zap_update(objset_t *os, uint64_t zapobj, const char *name,
int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx) int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx)
{ {
zap_t *zap; zap_t *zap;
mzap_ent_t *mze; ASSERTV(uint64_t oldval);
const uint64_t *intval = val; const uint64_t *intval = val;
zap_name_t *zn;
int err;
#ifdef ZFS_DEBUG #ifdef ZFS_DEBUG
uint64_t oldval;
/* /*
* If there is an old value, it shouldn't change across the * If there is an old value, it shouldn't change across the
@ -1325,10 +1281,11 @@ zap_update(objset_t *os, uint64_t zapobj, const char *name,
(void) zap_lookup(os, zapobj, name, 8, 1, &oldval); (void) zap_lookup(os, zapobj, name, 8, 1, &oldval);
#endif #endif
err = zap_lockdir(os, zapobj, tx, RW_WRITER, TRUE, TRUE, FTAG, &zap); int err =
if (err) zap_lockdir(os, zapobj, tx, RW_WRITER, TRUE, TRUE, FTAG, &zap);
if (err != 0)
return (err); return (err);
zn = zap_name_alloc(zap, name, 0); zap_name_t *zn = zap_name_alloc(zap, name, 0);
if (zn == NULL) { if (zn == NULL) {
zap_unlockdir(zap, FTAG); zap_unlockdir(zap, FTAG);
return (SET_ERROR(ENOTSUP)); return (SET_ERROR(ENOTSUP));
@ -1348,7 +1305,7 @@ zap_update(objset_t *os, uint64_t zapobj, const char *name,
} }
zap = zn->zn_zap; /* fzap_update() may change zap */ zap = zn->zn_zap; /* fzap_update() may change zap */
} else { } else {
mze = mze_find(zn); mzap_ent_t *mze = mze_find(zn);
if (mze != NULL) { if (mze != NULL) {
ASSERT3U(MZE_PHYS(zap, mze)->mze_value, ==, oldval); ASSERT3U(MZE_PHYS(zap, mze)->mze_value, ==, oldval);
MZE_PHYS(zap, mze)->mze_value = *intval; MZE_PHYS(zap, mze)->mze_value = *intval;
@ -1369,13 +1326,12 @@ zap_update_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx) int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx)
{ {
zap_t *zap; zap_t *zap;
zap_name_t *zn;
int err;
err = zap_lockdir(os, zapobj, tx, RW_WRITER, TRUE, TRUE, FTAG, &zap); int err =
if (err) zap_lockdir(os, zapobj, tx, RW_WRITER, TRUE, TRUE, FTAG, &zap);
if (err != 0)
return (err); return (err);
zn = zap_name_alloc_uint64(zap, key, key_numints); zap_name_t *zn = zap_name_alloc_uint64(zap, key, key_numints);
if (zn == NULL) { if (zn == NULL) {
zap_unlockdir(zap, FTAG); zap_unlockdir(zap, FTAG);
return (SET_ERROR(ENOTSUP)); return (SET_ERROR(ENOTSUP));
@ -1398,17 +1354,15 @@ static int
zap_remove_impl(zap_t *zap, const char *name, zap_remove_impl(zap_t *zap, const char *name,
matchtype_t mt, dmu_tx_t *tx) matchtype_t mt, dmu_tx_t *tx)
{ {
mzap_ent_t *mze;
zap_name_t *zn;
int err = 0; int err = 0;
zn = zap_name_alloc(zap, name, mt); zap_name_t *zn = zap_name_alloc(zap, name, mt);
if (zn == NULL) if (zn == NULL)
return (SET_ERROR(ENOTSUP)); return (SET_ERROR(ENOTSUP));
if (!zap->zap_ismicro) { if (!zap->zap_ismicro) {
err = fzap_remove(zn, tx); err = fzap_remove(zn, tx);
} else { } else {
mze = mze_find(zn); mzap_ent_t *mze = mze_find(zn);
if (mze == NULL) { if (mze == NULL) {
err = SET_ERROR(ENOENT); err = SET_ERROR(ENOENT);
} else { } else {
@ -1456,13 +1410,12 @@ zap_remove_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
int key_numints, dmu_tx_t *tx) int key_numints, dmu_tx_t *tx)
{ {
zap_t *zap; zap_t *zap;
int err;
zap_name_t *zn;
err = zap_lockdir(os, zapobj, tx, RW_WRITER, TRUE, FALSE, FTAG, &zap); int err =
if (err) zap_lockdir(os, zapobj, tx, RW_WRITER, TRUE, FALSE, FTAG, &zap);
if (err != 0)
return (err); return (err);
zn = zap_name_alloc_uint64(zap, key, key_numints); zap_name_t *zn = zap_name_alloc_uint64(zap, key, key_numints);
if (zn == NULL) { if (zn == NULL) {
zap_unlockdir(zap, FTAG); zap_unlockdir(zap, FTAG);
return (SET_ERROR(ENOTSUP)); return (SET_ERROR(ENOTSUP));
@ -1538,9 +1491,6 @@ int
zap_cursor_retrieve(zap_cursor_t *zc, zap_attribute_t *za) zap_cursor_retrieve(zap_cursor_t *zc, zap_attribute_t *za)
{ {
int err; int err;
avl_index_t idx;
mzap_ent_t mze_tofind;
mzap_ent_t *mze;
if (zc->zc_hash == -1ULL) if (zc->zc_hash == -1ULL)
return (SET_ERROR(ENOENT)); return (SET_ERROR(ENOENT));
@ -1549,7 +1499,7 @@ zap_cursor_retrieve(zap_cursor_t *zc, zap_attribute_t *za)
int hb; int hb;
err = zap_lockdir(zc->zc_objset, zc->zc_zapobj, NULL, err = zap_lockdir(zc->zc_objset, zc->zc_zapobj, NULL,
RW_READER, TRUE, FALSE, NULL, &zc->zc_zap); RW_READER, TRUE, FALSE, NULL, &zc->zc_zap);
if (err) if (err != 0)
return (err); return (err);
/* /*
@ -1569,10 +1519,14 @@ zap_cursor_retrieve(zap_cursor_t *zc, zap_attribute_t *za)
if (!zc->zc_zap->zap_ismicro) { if (!zc->zc_zap->zap_ismicro) {
err = fzap_cursor_retrieve(zc->zc_zap, zc, za); err = fzap_cursor_retrieve(zc->zc_zap, zc, za);
} else { } else {
avl_index_t idx;
mzap_ent_t mze_tofind;
mze_tofind.mze_hash = zc->zc_hash; mze_tofind.mze_hash = zc->zc_hash;
mze_tofind.mze_cd = zc->zc_cd; mze_tofind.mze_cd = zc->zc_cd;
mze = avl_find(&zc->zc_zap->zap_m.zap_avl, &mze_tofind, &idx); mzap_ent_t *mze =
avl_find(&zc->zc_zap->zap_m.zap_avl, &mze_tofind, &idx);
if (mze == NULL) { if (mze == NULL) {
mze = avl_nearest(&zc->zc_zap->zap_m.zap_avl, mze = avl_nearest(&zc->zc_zap->zap_m.zap_avl,
idx, AVL_AFTER); idx, AVL_AFTER);
@ -1609,11 +1563,11 @@ zap_cursor_advance(zap_cursor_t *zc)
int int
zap_get_stats(objset_t *os, uint64_t zapobj, zap_stats_t *zs) zap_get_stats(objset_t *os, uint64_t zapobj, zap_stats_t *zs)
{ {
int err;
zap_t *zap; zap_t *zap;
err = zap_lockdir(os, zapobj, NULL, RW_READER, TRUE, FALSE, FTAG, &zap); int err =
if (err) zap_lockdir(os, zapobj, NULL, RW_READER, TRUE, FALSE, FTAG, &zap);
if (err != 0)
return (err); return (err);
bzero(zs, sizeof (zap_stats_t)); bzero(zs, sizeof (zap_stats_t));