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 * Copyright (c) 2013 by Delphix. All rights reserved.
24 */
25
26 /*
27 * The 512-byte leaf is broken into 32 16-byte chunks.
28 * chunk number n means l_chunk[n], even though the header precedes it.
29 * the names are stored null-terminated.
30 */
31
32 #include <sys/zio.h>
33 #include <sys/spa.h>
34 #include <sys/dmu.h>
35 #include <sys/zfs_context.h>
36 #include <sys/fs/zfs.h>
37 #include <sys/zap.h>
38 #include <sys/zap_impl.h>
39 #include <sys/zap_leaf.h>
40 #include <sys/arc.h>
41
42 static uint16_t *zap_leaf_rehash_entry(zap_leaf_t *l, uint16_t entry);
43
88 {
89 switch (len) {
90 case 1:
91 return (*(uint8_t *)addr);
92 case 2:
93 return (*(uint16_t *)addr);
94 case 4:
95 return (*(uint32_t *)addr);
96 case 8:
97 return (*(uint64_t *)addr);
98 }
99 ASSERT(!"bad int len");
100 return (0xFEEDFACEDEADBEEFULL);
101 }
102
103 void
104 zap_leaf_byteswap(zap_leaf_phys_t *buf, int size)
105 {
106 int i;
107 zap_leaf_t l;
108 l.l_bs = highbit(size)-1;
109 l.l_phys = buf;
110
111 buf->l_hdr.lh_block_type = BSWAP_64(buf->l_hdr.lh_block_type);
112 buf->l_hdr.lh_prefix = BSWAP_64(buf->l_hdr.lh_prefix);
113 buf->l_hdr.lh_magic = BSWAP_32(buf->l_hdr.lh_magic);
114 buf->l_hdr.lh_nfree = BSWAP_16(buf->l_hdr.lh_nfree);
115 buf->l_hdr.lh_nentries = BSWAP_16(buf->l_hdr.lh_nentries);
116 buf->l_hdr.lh_prefix_len = BSWAP_16(buf->l_hdr.lh_prefix_len);
117 buf->l_hdr.lh_freelist = BSWAP_16(buf->l_hdr.lh_freelist);
118
119 for (i = 0; i < ZAP_LEAF_HASH_NUMENTRIES(&l); i++)
120 buf->l_hash[i] = BSWAP_16(buf->l_hash[i]);
121
122 for (i = 0; i < ZAP_LEAF_NUMCHUNKS(&l); i++) {
123 zap_leaf_chunk_t *lc = &ZAP_LEAF_CHUNK(&l, i);
124 struct zap_leaf_entry *le;
125
126 switch (lc->l_free.lf_type) {
127 case ZAP_CHUNK_ENTRY:
128 le = &lc->l_entry;
140 case ZAP_CHUNK_FREE:
141 lc->l_free.lf_type = BSWAP_8(lc->l_free.lf_type);
142 lc->l_free.lf_next = BSWAP_16(lc->l_free.lf_next);
143 break;
144 case ZAP_CHUNK_ARRAY:
145 lc->l_array.la_type = BSWAP_8(lc->l_array.la_type);
146 lc->l_array.la_next = BSWAP_16(lc->l_array.la_next);
147 /* la_array doesn't need swapping */
148 break;
149 default:
150 ASSERT(!"bad leaf type");
151 }
152 }
153 }
154
155 void
156 zap_leaf_init(zap_leaf_t *l, boolean_t sort)
157 {
158 int i;
159
160 l->l_bs = highbit(l->l_dbuf->db_size)-1;
161 zap_memset(&l->l_phys->l_hdr, 0, sizeof (struct zap_leaf_header));
162 zap_memset(l->l_phys->l_hash, CHAIN_END, 2*ZAP_LEAF_HASH_NUMENTRIES(l));
163 for (i = 0; i < ZAP_LEAF_NUMCHUNKS(l); i++) {
164 ZAP_LEAF_CHUNK(l, i).l_free.lf_type = ZAP_CHUNK_FREE;
165 ZAP_LEAF_CHUNK(l, i).l_free.lf_next = i+1;
166 }
167 ZAP_LEAF_CHUNK(l, ZAP_LEAF_NUMCHUNKS(l)-1).l_free.lf_next = CHAIN_END;
168 l->l_phys->l_hdr.lh_block_type = ZBT_LEAF;
169 l->l_phys->l_hdr.lh_magic = ZAP_LEAF_MAGIC;
170 l->l_phys->l_hdr.lh_nfree = ZAP_LEAF_NUMCHUNKS(l);
171 if (sort)
172 l->l_phys->l_hdr.lh_flags |= ZLF_ENTRIES_CDSORTED;
173 }
174
175 /*
176 * Routines which manipulate leaf chunks (l_chunk[]).
177 */
178
179 static uint16_t
180 zap_leaf_chunk_alloc(zap_leaf_t *l)
|
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 * Copyright (c) 2013, 2014 by Delphix. All rights reserved.
24 */
25
26 /*
27 * The 512-byte leaf is broken into 32 16-byte chunks.
28 * chunk number n means l_chunk[n], even though the header precedes it.
29 * the names are stored null-terminated.
30 */
31
32 #include <sys/zio.h>
33 #include <sys/spa.h>
34 #include <sys/dmu.h>
35 #include <sys/zfs_context.h>
36 #include <sys/fs/zfs.h>
37 #include <sys/zap.h>
38 #include <sys/zap_impl.h>
39 #include <sys/zap_leaf.h>
40 #include <sys/arc.h>
41
42 static uint16_t *zap_leaf_rehash_entry(zap_leaf_t *l, uint16_t entry);
43
88 {
89 switch (len) {
90 case 1:
91 return (*(uint8_t *)addr);
92 case 2:
93 return (*(uint16_t *)addr);
94 case 4:
95 return (*(uint32_t *)addr);
96 case 8:
97 return (*(uint64_t *)addr);
98 }
99 ASSERT(!"bad int len");
100 return (0xFEEDFACEDEADBEEFULL);
101 }
102
103 void
104 zap_leaf_byteswap(zap_leaf_phys_t *buf, int size)
105 {
106 int i;
107 zap_leaf_t l;
108 l.l_bs = highbit64(size) - 1;
109 l.l_phys = buf;
110
111 buf->l_hdr.lh_block_type = BSWAP_64(buf->l_hdr.lh_block_type);
112 buf->l_hdr.lh_prefix = BSWAP_64(buf->l_hdr.lh_prefix);
113 buf->l_hdr.lh_magic = BSWAP_32(buf->l_hdr.lh_magic);
114 buf->l_hdr.lh_nfree = BSWAP_16(buf->l_hdr.lh_nfree);
115 buf->l_hdr.lh_nentries = BSWAP_16(buf->l_hdr.lh_nentries);
116 buf->l_hdr.lh_prefix_len = BSWAP_16(buf->l_hdr.lh_prefix_len);
117 buf->l_hdr.lh_freelist = BSWAP_16(buf->l_hdr.lh_freelist);
118
119 for (i = 0; i < ZAP_LEAF_HASH_NUMENTRIES(&l); i++)
120 buf->l_hash[i] = BSWAP_16(buf->l_hash[i]);
121
122 for (i = 0; i < ZAP_LEAF_NUMCHUNKS(&l); i++) {
123 zap_leaf_chunk_t *lc = &ZAP_LEAF_CHUNK(&l, i);
124 struct zap_leaf_entry *le;
125
126 switch (lc->l_free.lf_type) {
127 case ZAP_CHUNK_ENTRY:
128 le = &lc->l_entry;
140 case ZAP_CHUNK_FREE:
141 lc->l_free.lf_type = BSWAP_8(lc->l_free.lf_type);
142 lc->l_free.lf_next = BSWAP_16(lc->l_free.lf_next);
143 break;
144 case ZAP_CHUNK_ARRAY:
145 lc->l_array.la_type = BSWAP_8(lc->l_array.la_type);
146 lc->l_array.la_next = BSWAP_16(lc->l_array.la_next);
147 /* la_array doesn't need swapping */
148 break;
149 default:
150 ASSERT(!"bad leaf type");
151 }
152 }
153 }
154
155 void
156 zap_leaf_init(zap_leaf_t *l, boolean_t sort)
157 {
158 int i;
159
160 l->l_bs = highbit64(l->l_dbuf->db_size) - 1;
161 zap_memset(&l->l_phys->l_hdr, 0, sizeof (struct zap_leaf_header));
162 zap_memset(l->l_phys->l_hash, CHAIN_END, 2*ZAP_LEAF_HASH_NUMENTRIES(l));
163 for (i = 0; i < ZAP_LEAF_NUMCHUNKS(l); i++) {
164 ZAP_LEAF_CHUNK(l, i).l_free.lf_type = ZAP_CHUNK_FREE;
165 ZAP_LEAF_CHUNK(l, i).l_free.lf_next = i+1;
166 }
167 ZAP_LEAF_CHUNK(l, ZAP_LEAF_NUMCHUNKS(l)-1).l_free.lf_next = CHAIN_END;
168 l->l_phys->l_hdr.lh_block_type = ZBT_LEAF;
169 l->l_phys->l_hdr.lh_magic = ZAP_LEAF_MAGIC;
170 l->l_phys->l_hdr.lh_nfree = ZAP_LEAF_NUMCHUNKS(l);
171 if (sort)
172 l->l_phys->l_hdr.lh_flags |= ZLF_ENTRIES_CDSORTED;
173 }
174
175 /*
176 * Routines which manipulate leaf chunks (l_chunk[]).
177 */
178
179 static uint16_t
180 zap_leaf_chunk_alloc(zap_leaf_t *l)
|