author | Jeff Bonwick <Jeff.Bonwick@Sun.COM> |
Sun, 01 Nov 2009 14:14:46 -0800 | |
changeset 10922 | e2081f502306 |
parent 10612 | 89423355fa6f |
child 11165 | 68184eb5449e |
permissions | -rw-r--r-- |
789 | 1 |
/* |
2 |
* CDDL HEADER START |
|
3 |
* |
|
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 | 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 |
/* |
|
9653
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
5384
diff
changeset
|
22 |
* Copyright 2009 Sun Microsystems, Inc. All rights reserved. |
789 | 23 |
* Use is subject to license terms. |
24 |
*/ |
|
25 |
||
26 |
#ifndef _SYS_ZAP_IMPL_H |
|
27 |
#define _SYS_ZAP_IMPL_H |
|
28 |
||
29 |
#include <sys/zap.h> |
|
30 |
#include <sys/zfs_context.h> |
|
31 |
#include <sys/avl.h> |
|
32 |
||
33 |
#ifdef __cplusplus |
|
34 |
extern "C" { |
|
35 |
#endif |
|
36 |
||
1491
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
37 |
extern int fzap_default_block_shift; |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
38 |
|
2856 | 39 |
#define ZAP_MAGIC 0x2F52AB2ABULL |
789 | 40 |
|
1491
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
41 |
#define FZAP_BLOCK_SHIFT(zap) ((zap)->zap_f.zap_block_shift) |
789 | 42 |
|
43 |
#define MZAP_ENT_LEN 64 |
|
44 |
#define MZAP_NAME_LEN (MZAP_ENT_LEN - 8 - 4 - 2) |
|
1491
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
45 |
#define MZAP_MAX_BLKSHIFT SPA_MAXBLOCKSHIFT |
789 | 46 |
#define MZAP_MAX_BLKSZ (1 << MZAP_MAX_BLKSHIFT) |
47 |
||
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10612
diff
changeset
|
48 |
#define ZAP_NEED_CD (-1U) |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10612
diff
changeset
|
49 |
|
789 | 50 |
typedef struct mzap_ent_phys { |
51 |
uint64_t mze_value; |
|
52 |
uint32_t mze_cd; |
|
53 |
uint16_t mze_pad; /* in case we want to chain them someday */ |
|
54 |
char mze_name[MZAP_NAME_LEN]; |
|
55 |
} mzap_ent_phys_t; |
|
56 |
||
57 |
typedef struct mzap_phys { |
|
58 |
uint64_t mz_block_type; /* ZBT_MICRO */ |
|
59 |
uint64_t mz_salt; |
|
5331 | 60 |
uint64_t mz_normflags; |
61 |
uint64_t mz_pad[5]; |
|
789 | 62 |
mzap_ent_phys_t mz_chunk[1]; |
63 |
/* actually variable size depending on block size */ |
|
64 |
} mzap_phys_t; |
|
65 |
||
66 |
typedef struct mzap_ent { |
|
67 |
avl_node_t mze_node; |
|
68 |
int mze_chunkid; |
|
69 |
uint64_t mze_hash; |
|
70 |
mzap_ent_phys_t mze_phys; |
|
71 |
} mzap_ent_t; |
|
72 |
||
73 |
/* |
|
74 |
* The (fat) zap is stored in one object. It is an array of |
|
1491
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
75 |
* 1<<FZAP_BLOCK_SHIFT byte blocks. The layout looks like one of: |
789 | 76 |
* |
77 |
* ptrtbl fits in first block: |
|
78 |
* [zap_phys_t zap_ptrtbl_shift < 6] [zap_leaf_t] ... |
|
79 |
* |
|
80 |
* ptrtbl too big for first block: |
|
81 |
* [zap_phys_t zap_ptrtbl_shift >= 6] [zap_leaf_t] [ptrtbl] ... |
|
82 |
* |
|
83 |
*/ |
|
84 |
||
85 |
struct dmu_buf; |
|
86 |
struct zap_leaf; |
|
87 |
||
88 |
#define ZBT_LEAF ((1ULL << 63) + 0) |
|
89 |
#define ZBT_HEADER ((1ULL << 63) + 1) |
|
90 |
#define ZBT_MICRO ((1ULL << 63) + 3) |
|
91 |
/* any other values are ptrtbl blocks */ |
|
92 |
||
1491
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
93 |
/* |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
94 |
* the embedded pointer table takes up half a block: |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
95 |
* block size / entry size (2^3) / 2 |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
96 |
*/ |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
97 |
#define ZAP_EMBEDDED_PTRTBL_SHIFT(zap) (FZAP_BLOCK_SHIFT(zap) - 3 - 1) |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
98 |
|
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
99 |
/* |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
100 |
* The embedded pointer table starts half-way through the block. Since |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
101 |
* the pointer table itself is half the block, it starts at (64-bit) |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
102 |
* word number (1<<ZAP_EMBEDDED_PTRTBL_SHIFT(zap)). |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
103 |
*/ |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
104 |
#define ZAP_EMBEDDED_PTRTBL_ENT(zap, idx) \ |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
105 |
((uint64_t *)(zap)->zap_f.zap_phys) \ |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
106 |
[(idx) + (1<<ZAP_EMBEDDED_PTRTBL_SHIFT(zap))] |
789 | 107 |
|
108 |
/* |
|
109 |
* TAKE NOTE: |
|
110 |
* If zap_phys_t is modified, zap_byteswap() must be modified. |
|
111 |
*/ |
|
112 |
typedef struct zap_phys { |
|
113 |
uint64_t zap_block_type; /* ZBT_HEADER */ |
|
114 |
uint64_t zap_magic; /* ZAP_MAGIC */ |
|
115 |
||
116 |
struct zap_table_phys { |
|
117 |
uint64_t zt_blk; /* starting block number */ |
|
118 |
uint64_t zt_numblks; /* number of blocks */ |
|
119 |
uint64_t zt_shift; /* bits to index it */ |
|
120 |
uint64_t zt_nextblk; /* next (larger) copy start block */ |
|
121 |
uint64_t zt_blks_copied; /* number source blocks copied */ |
|
122 |
} zap_ptrtbl; |
|
123 |
||
124 |
uint64_t zap_freeblk; /* the next free block */ |
|
125 |
uint64_t zap_num_leafs; /* number of leafs */ |
|
126 |
uint64_t zap_num_entries; /* number of entries */ |
|
127 |
uint64_t zap_salt; /* salt to stir into hash function */ |
|
5331 | 128 |
uint64_t zap_normflags; /* flags for u8_textprep_str() */ |
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10612
diff
changeset
|
129 |
uint64_t zap_flags; /* zap_flags_t */ |
1491
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
130 |
/* |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
131 |
* This structure is followed by padding, and then the embedded |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
132 |
* pointer table. The embedded pointer table takes up second |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
133 |
* half of the block. It is accessed using the |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
134 |
* ZAP_EMBEDDED_PTRTBL_ENT() macro. |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
135 |
*/ |
789 | 136 |
} zap_phys_t; |
137 |
||
138 |
typedef struct zap_table_phys zap_table_phys_t; |
|
139 |
||
140 |
typedef struct zap { |
|
141 |
objset_t *zap_objset; |
|
142 |
uint64_t zap_object; |
|
143 |
struct dmu_buf *zap_dbuf; |
|
144 |
krwlock_t zap_rwlock; |
|
5331 | 145 |
boolean_t zap_ismicro; |
146 |
int zap_normflags; |
|
789 | 147 |
uint64_t zap_salt; |
148 |
union { |
|
149 |
struct { |
|
150 |
zap_phys_t *zap_phys; |
|
151 |
||
152 |
/* |
|
153 |
* zap_num_entries_mtx protects |
|
154 |
* zap_num_entries |
|
155 |
*/ |
|
156 |
kmutex_t zap_num_entries_mtx; |
|
1491
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
885
diff
changeset
|
157 |
int zap_block_shift; |
789 | 158 |
} zap_fat; |
159 |
struct { |
|
160 |
mzap_phys_t *zap_phys; |
|
161 |
int16_t zap_num_entries; |
|
162 |
int16_t zap_num_chunks; |
|
163 |
int16_t zap_alloc_next; |
|
164 |
avl_tree_t zap_avl; |
|
165 |
} zap_micro; |
|
166 |
} zap_u; |
|
167 |
} zap_t; |
|
168 |
||
5331 | 169 |
typedef struct zap_name { |
170 |
zap_t *zn_zap; |
|
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10612
diff
changeset
|
171 |
int zn_key_intlen; |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10612
diff
changeset
|
172 |
const void *zn_key_orig; |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10612
diff
changeset
|
173 |
int zn_key_orig_len; |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10612
diff
changeset
|
174 |
const void *zn_key_norm; |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10612
diff
changeset
|
175 |
int zn_key_norm_len; |
5331 | 176 |
uint64_t zn_hash; |
177 |
matchtype_t zn_matchtype; |
|
178 |
char zn_normbuf[ZAP_MAXNAMELEN]; |
|
179 |
} zap_name_t; |
|
180 |
||
789 | 181 |
#define zap_f zap_u.zap_fat |
182 |
#define zap_m zap_u.zap_micro |
|
183 |
||
5331 | 184 |
boolean_t zap_match(zap_name_t *zn, const char *matchname); |
789 | 185 |
int zap_lockdir(objset_t *os, uint64_t obj, dmu_tx_t *tx, |
5384
8eba72d775e9
6623831 assertion failed in dmu_tx_willuse_space() from mzap_upgrade()
ahrens
parents:
5331
diff
changeset
|
186 |
krw_t lti, boolean_t fatreader, boolean_t adding, zap_t **zapp); |
789 | 187 |
void zap_unlockdir(zap_t *zap); |
2641 | 188 |
void zap_evict(dmu_buf_t *db, void *vmzap); |
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10612
diff
changeset
|
189 |
zap_name_t *zap_name_alloc(zap_t *zap, const char *key, matchtype_t mt); |
5331 | 190 |
void zap_name_free(zap_name_t *zn); |
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10612
diff
changeset
|
191 |
int zap_hashbits(zap_t *zap); |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10612
diff
changeset
|
192 |
uint32_t zap_maxcd(zap_t *zap); |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10612
diff
changeset
|
193 |
uint64_t zap_getflags(zap_t *zap); |
789 | 194 |
|
195 |
#define ZAP_HASH_IDX(hash, n) (((n) == 0) ? 0 : ((hash) >> (64 - (n)))) |
|
196 |
||
197 |
void fzap_byteswap(void *buf, size_t size); |
|
198 |
int fzap_count(zap_t *zap, uint64_t *count); |
|
5331 | 199 |
int fzap_lookup(zap_name_t *zn, |
200 |
uint64_t integer_size, uint64_t num_integers, void *buf, |
|
201 |
char *realname, int rn_len, boolean_t *normalization_conflictp); |
|
9653
a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
5384
diff
changeset
|
202 |
int 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:
5384
diff
changeset
|
203 |
uint64_t *tooverwrite); |
5331 | 204 |
int fzap_add(zap_name_t *zn, uint64_t integer_size, uint64_t num_integers, |
789 | 205 |
const void *val, dmu_tx_t *tx); |
5331 | 206 |
int fzap_update(zap_name_t *zn, |
789 | 207 |
int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx); |
5331 | 208 |
int fzap_length(zap_name_t *zn, |
789 | 209 |
uint64_t *integer_size, uint64_t *num_integers); |
5331 | 210 |
int fzap_remove(zap_name_t *zn, dmu_tx_t *tx); |
789 | 211 |
int fzap_cursor_retrieve(zap_t *zap, zap_cursor_t *zc, zap_attribute_t *za); |
212 |
void fzap_get_stats(zap_t *zap, zap_stats_t *zs); |
|
885
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
213 |
void zap_put_leaf(struct zap_leaf *l); |
789 | 214 |
|
5331 | 215 |
int fzap_add_cd(zap_name_t *zn, |
789 | 216 |
uint64_t integer_size, uint64_t num_integers, |
1544 | 217 |
const void *val, uint32_t cd, dmu_tx_t *tx); |
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10612
diff
changeset
|
218 |
void fzap_upgrade(zap_t *zap, dmu_tx_t *tx, zap_flags_t flags); |
10612
89423355fa6f
6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents:
9653
diff
changeset
|
219 |
int fzap_cursor_move_to_key(zap_cursor_t *zc, zap_name_t *zn); |
789 | 220 |
|
221 |
#ifdef __cplusplus |
|
222 |
} |
|
223 |
#endif |
|
224 |
||
225 |
#endif /* _SYS_ZAP_IMPL_H */ |