4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #ifndef _SYS_ZAP_IMPL_H
27 #define _SYS_ZAP_IMPL_H
29 #pragma ident "%Z%%M% %I% %E% SMI"
32 #include <sys/zfs_context.h>
39 extern int fzap_default_block_shift;
41 #define ZAP_MAGIC 0x2F52AB2ABULL
43 #define FZAP_BLOCK_SHIFT(zap) ((zap)->zap_f.zap_block_shift)
45 #define ZAP_MAXCD (uint32_t)(-1)
46 #define ZAP_HASHBITS 28
47 #define MZAP_ENT_LEN 64
48 #define MZAP_NAME_LEN (MZAP_ENT_LEN - 8 - 4 - 2)
49 #define MZAP_MAX_BLKSHIFT SPA_MAXBLOCKSHIFT
50 #define MZAP_MAX_BLKSZ (1 << MZAP_MAX_BLKSHIFT)
52 typedef struct mzap_ent_phys {
55 uint16_t mze_pad; /* in case we want to chain them someday */
56 char mze_name[MZAP_NAME_LEN];
59 typedef struct mzap_phys {
60 uint64_t mz_block_type; /* ZBT_MICRO */
63 mzap_ent_phys_t mz_chunk[1];
64 /* actually variable size depending on block size */
67 typedef struct mzap_ent {
71 mzap_ent_phys_t mze_phys;
76 * The (fat) zap is stored in one object. It is an array of
77 * 1<<FZAP_BLOCK_SHIFT byte blocks. The layout looks like one of:
79 * ptrtbl fits in first block:
80 * [zap_phys_t zap_ptrtbl_shift < 6] [zap_leaf_t] ...
82 * ptrtbl too big for first block:
83 * [zap_phys_t zap_ptrtbl_shift >= 6] [zap_leaf_t] [ptrtbl] ...
90 #define ZBT_LEAF ((1ULL << 63) + 0)
91 #define ZBT_HEADER ((1ULL << 63) + 1)
92 #define ZBT_MICRO ((1ULL << 63) + 3)
93 /* any other values are ptrtbl blocks */
96 * the embedded pointer table takes up half a block:
97 * block size / entry size (2^3) / 2
99 #define ZAP_EMBEDDED_PTRTBL_SHIFT(zap) (FZAP_BLOCK_SHIFT(zap) - 3 - 1)
102 * The embedded pointer table starts half-way through the block. Since
103 * the pointer table itself is half the block, it starts at (64-bit)
104 * word number (1<<ZAP_EMBEDDED_PTRTBL_SHIFT(zap)).
106 #define ZAP_EMBEDDED_PTRTBL_ENT(zap, idx) \
107 ((uint64_t *)(zap)->zap_f.zap_phys) \
108 [(idx) + (1<<ZAP_EMBEDDED_PTRTBL_SHIFT(zap))]
112 * If zap_phys_t is modified, zap_byteswap() must be modified.
114 typedef struct zap_phys {
115 uint64_t zap_block_type; /* ZBT_HEADER */
116 uint64_t zap_magic; /* ZAP_MAGIC */
118 struct zap_table_phys {
119 uint64_t zt_blk; /* starting block number */
120 uint64_t zt_numblks; /* number of blocks */
121 uint64_t zt_shift; /* bits to index it */
122 uint64_t zt_nextblk; /* next (larger) copy start block */
123 uint64_t zt_blks_copied; /* number source blocks copied */
126 uint64_t zap_freeblk; /* the next free block */
127 uint64_t zap_num_leafs; /* number of leafs */
128 uint64_t zap_num_entries; /* number of entries */
129 uint64_t zap_salt; /* salt to stir into hash function */
131 * This structure is followed by padding, and then the embedded
132 * pointer table. The embedded pointer table takes up second
133 * half of the block. It is accessed using the
134 * ZAP_EMBEDDED_PTRTBL_ENT() macro.
138 typedef struct zap_table_phys zap_table_phys_t;
141 objset_t *zap_objset;
143 struct dmu_buf *zap_dbuf;
144 krwlock_t zap_rwlock;
149 zap_phys_t *zap_phys;
152 * zap_num_entries_mtx protects
155 kmutex_t zap_num_entries_mtx;
159 mzap_phys_t *zap_phys;
160 int16_t zap_num_entries;
161 int16_t zap_num_chunks;
162 int16_t zap_alloc_next;
168 #define zap_f zap_u.zap_fat
169 #define zap_m zap_u.zap_micro
171 uint64_t zap_hash(zap_t *zap, const char *name);
172 int zap_lockdir(objset_t *os, uint64_t obj, dmu_tx_t *tx,
173 krw_t lti, int fatreader, zap_t **zapp);
174 void zap_unlockdir(zap_t *zap);
175 void zap_evict(dmu_buf_t *db, void *vmzap);
177 #define ZAP_HASH_IDX(hash, n) (((n) == 0) ? 0 : ((hash) >> (64 - (n))))
179 void fzap_byteswap(void *buf, size_t size);
180 int fzap_count(zap_t *zap, uint64_t *count);
181 int fzap_lookup(zap_t *zap, const char *name,
182 uint64_t integer_size, uint64_t num_integers, void *buf);
183 int fzap_add(zap_t *zap, const char *name,
184 uint64_t integer_size, uint64_t num_integers,
185 const void *val, dmu_tx_t *tx);
186 int fzap_update(zap_t *zap, const char *name,
187 int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx);
188 int fzap_length(zap_t *zap, const char *name,
189 uint64_t *integer_size, uint64_t *num_integers);
190 int fzap_remove(zap_t *zap, const char *name, dmu_tx_t *tx);
191 int fzap_cursor_retrieve(zap_t *zap, zap_cursor_t *zc, zap_attribute_t *za);
192 void fzap_get_stats(zap_t *zap, zap_stats_t *zs);
193 void zap_put_leaf(struct zap_leaf *l);
195 int fzap_add_cd(zap_t *zap, const char *name,
196 uint64_t integer_size, uint64_t num_integers,
197 const void *val, uint32_t cd, dmu_tx_t *tx);
198 void fzap_upgrade(zap_t *zap, dmu_tx_t *tx);
204 #endif /* _SYS_ZAP_IMPL_H */