]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zap_impl.h
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / sys / cddl / contrib / opensolaris / uts / common / fs / zfs / sys / zap_impl.h
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23  */
24
25 #ifndef _SYS_ZAP_IMPL_H
26 #define _SYS_ZAP_IMPL_H
27
28 #include <sys/zap.h>
29 #include <sys/zfs_context.h>
30 #include <sys/avl.h>
31
32 #ifdef  __cplusplus
33 extern "C" {
34 #endif
35
36 extern int fzap_default_block_shift;
37
38 #define ZAP_MAGIC 0x2F52AB2ABULL
39
40 #define FZAP_BLOCK_SHIFT(zap)   ((zap)->zap_f.zap_block_shift)
41
42 #define MZAP_ENT_LEN            64
43 #define MZAP_NAME_LEN           (MZAP_ENT_LEN - 8 - 4 - 2)
44 #define MZAP_MAX_BLKSZ          SPA_OLD_MAXBLOCKSIZE
45
46 #define ZAP_NEED_CD             (-1U)
47
48 typedef struct mzap_ent_phys {
49         uint64_t mze_value;
50         uint32_t mze_cd;
51         uint16_t mze_pad;       /* in case we want to chain them someday */
52         char mze_name[MZAP_NAME_LEN];
53 } mzap_ent_phys_t;
54
55 typedef struct mzap_phys {
56         uint64_t mz_block_type; /* ZBT_MICRO */
57         uint64_t mz_salt;
58         uint64_t mz_normflags;
59         uint64_t mz_pad[5];
60         mzap_ent_phys_t mz_chunk[1];
61         /* actually variable size depending on block size */
62 } mzap_phys_t;
63
64 typedef struct mzap_ent {
65         avl_node_t mze_node;
66         int mze_chunkid;
67         uint64_t mze_hash;
68         uint32_t mze_cd; /* copy from mze_phys->mze_cd */
69 } mzap_ent_t;
70
71 #define MZE_PHYS(zap, mze) \
72         (&zap_m_phys(zap)->mz_chunk[(mze)->mze_chunkid])
73
74 /*
75  * The (fat) zap is stored in one object. It is an array of
76  * 1<<FZAP_BLOCK_SHIFT byte blocks. The layout looks like one of:
77  *
78  * ptrtbl fits in first block:
79  *      [zap_phys_t zap_ptrtbl_shift < 6] [zap_leaf_t] ...
80  *
81  * ptrtbl too big for first block:
82  *      [zap_phys_t zap_ptrtbl_shift >= 6] [zap_leaf_t] [ptrtbl] ...
83  *
84  */
85
86 struct dmu_buf;
87 struct zap_leaf;
88
89 #define ZBT_LEAF                ((1ULL << 63) + 0)
90 #define ZBT_HEADER              ((1ULL << 63) + 1)
91 #define ZBT_MICRO               ((1ULL << 63) + 3)
92 /* any other values are ptrtbl blocks */
93
94 /*
95  * the embedded pointer table takes up half a block:
96  * block size / entry size (2^3) / 2
97  */
98 #define ZAP_EMBEDDED_PTRTBL_SHIFT(zap) (FZAP_BLOCK_SHIFT(zap) - 3 - 1)
99
100 /*
101  * The embedded pointer table starts half-way through the block.  Since
102  * the pointer table itself is half the block, it starts at (64-bit)
103  * word number (1<<ZAP_EMBEDDED_PTRTBL_SHIFT(zap)).
104  */
105 #define ZAP_EMBEDDED_PTRTBL_ENT(zap, idx) \
106         ((uint64_t *)zap_f_phys(zap)) \
107         [(idx) + (1<<ZAP_EMBEDDED_PTRTBL_SHIFT(zap))]
108
109 /*
110  * TAKE NOTE:
111  * If zap_phys_t is modified, zap_byteswap() must be modified.
112  */
113 typedef struct zap_phys {
114         uint64_t zap_block_type;        /* ZBT_HEADER */
115         uint64_t zap_magic;             /* ZAP_MAGIC */
116
117         struct zap_table_phys {
118                 uint64_t zt_blk;        /* starting block number */
119                 uint64_t zt_numblks;    /* number of blocks */
120                 uint64_t zt_shift;      /* bits to index it */
121                 uint64_t zt_nextblk;    /* next (larger) copy start block */
122                 uint64_t zt_blks_copied; /* number source blocks copied */
123         } zap_ptrtbl;
124
125         uint64_t zap_freeblk;           /* the next free block */
126         uint64_t zap_num_leafs;         /* number of leafs */
127         uint64_t zap_num_entries;       /* number of entries */
128         uint64_t zap_salt;              /* salt to stir into hash function */
129         uint64_t zap_normflags;         /* flags for u8_textprep_str() */
130         uint64_t zap_flags;             /* zap_flags_t */
131         /*
132          * This structure is followed by padding, and then the embedded
133          * pointer table.  The embedded pointer table takes up second
134          * half of the block.  It is accessed using the
135          * ZAP_EMBEDDED_PTRTBL_ENT() macro.
136          */
137 } zap_phys_t;
138
139 typedef struct zap_table_phys zap_table_phys_t;
140
141 typedef struct zap {
142         objset_t *zap_objset;
143         uint64_t zap_object;
144         struct dmu_buf *zap_dbuf;
145         krwlock_t zap_rwlock;
146         boolean_t zap_ismicro;
147         int zap_normflags;
148         uint64_t zap_salt;
149         union {
150                 struct {
151                         /*
152                          * zap_num_entries_mtx protects
153                          * zap_num_entries
154                          */
155                         kmutex_t zap_num_entries_mtx;
156                         int zap_block_shift;
157                 } zap_fat;
158                 struct {
159                         int16_t zap_num_entries;
160                         int16_t zap_num_chunks;
161                         int16_t zap_alloc_next;
162                         avl_tree_t zap_avl;
163                 } zap_micro;
164         } zap_u;
165 } zap_t;
166
167 inline zap_phys_t *
168 zap_f_phys(zap_t *zap)
169 {
170         return (zap->zap_dbuf->db_data);
171 }
172
173 inline mzap_phys_t *
174 zap_m_phys(zap_t *zap)
175 {
176         return (zap->zap_dbuf->db_data);
177 }
178
179 typedef struct zap_name {
180         zap_t *zn_zap;
181         int zn_key_intlen;
182         const void *zn_key_orig;
183         int zn_key_orig_numints;
184         const void *zn_key_norm;
185         int zn_key_norm_numints;
186         uint64_t zn_hash;
187         matchtype_t zn_matchtype;
188         char zn_normbuf[ZAP_MAXNAMELEN];
189 } zap_name_t;
190
191 #define zap_f   zap_u.zap_fat
192 #define zap_m   zap_u.zap_micro
193
194 boolean_t zap_match(zap_name_t *zn, const char *matchname);
195 int zap_lockdir(objset_t *os, uint64_t obj, dmu_tx_t *tx,
196     krw_t lti, boolean_t fatreader, boolean_t adding, zap_t **zapp);
197 void zap_unlockdir(zap_t *zap);
198 void zap_evict(dmu_buf_t *db, void *vmzap);
199 zap_name_t *zap_name_alloc(zap_t *zap, const char *key, matchtype_t mt);
200 void zap_name_free(zap_name_t *zn);
201 int zap_hashbits(zap_t *zap);
202 uint32_t zap_maxcd(zap_t *zap);
203 uint64_t zap_getflags(zap_t *zap);
204
205 #define ZAP_HASH_IDX(hash, n) (((n) == 0) ? 0 : ((hash) >> (64 - (n))))
206
207 void fzap_byteswap(void *buf, size_t size);
208 int fzap_count(zap_t *zap, uint64_t *count);
209 int fzap_lookup(zap_name_t *zn,
210     uint64_t integer_size, uint64_t num_integers, void *buf,
211     char *realname, int rn_len, boolean_t *normalization_conflictp);
212 void fzap_prefetch(zap_name_t *zn);
213 int fzap_count_write(zap_name_t *zn, int add, uint64_t *towrite,
214     uint64_t *tooverwrite);
215 int fzap_add(zap_name_t *zn, uint64_t integer_size, uint64_t num_integers,
216     const void *val, dmu_tx_t *tx);
217 int fzap_update(zap_name_t *zn,
218     int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx);
219 int fzap_length(zap_name_t *zn,
220     uint64_t *integer_size, uint64_t *num_integers);
221 int fzap_remove(zap_name_t *zn, dmu_tx_t *tx);
222 int fzap_cursor_retrieve(zap_t *zap, zap_cursor_t *zc, zap_attribute_t *za);
223 void fzap_get_stats(zap_t *zap, zap_stats_t *zs);
224 void zap_put_leaf(struct zap_leaf *l);
225
226 int fzap_add_cd(zap_name_t *zn,
227     uint64_t integer_size, uint64_t num_integers,
228     const void *val, uint32_t cd, dmu_tx_t *tx);
229 void fzap_upgrade(zap_t *zap, dmu_tx_t *tx, zap_flags_t flags);
230 int fzap_cursor_move_to_key(zap_cursor_t *zc, zap_name_t *zn);
231
232 #ifdef  __cplusplus
233 }
234 #endif
235
236 #endif /* _SYS_ZAP_IMPL_H */