4141#include <sys/zap_leaf.h>
4242#include <sys/arc.h>
4343
44- static uint16_t * zap_leaf_rehash_entry (zap_leaf_t * l , uint16_t entry );
44+ static uint16_t * zap_leaf_rehash_entry (zap_leaf_t * l , struct zap_leaf_entry * le ,
45+ uint16_t entry );
4546
4647#define CHAIN_END 0xffff /* end of the chunk chain */
4748
@@ -52,16 +53,6 @@ static uint16_t *zap_leaf_rehash_entry(zap_leaf_t *l, uint16_t entry);
5253
5354#define LEAF_HASH_ENTPTR (l , h ) (&zap_leaf_phys(l)->l_hash[LEAF_HASH(l, h)])
5455
55- static void
56- zap_memset (void * a , int c , size_t n )
57- {
58- char * cp = a ;
59- char * cpend = cp + n ;
60-
61- while (cp < cpend )
62- * cp ++ = c ;
63- }
64-
6556static void
6657stv (int len , void * addr , uint64_t value )
6758{
@@ -79,7 +70,7 @@ stv(int len, void *addr, uint64_t value)
7970 * (uint64_t * )addr = value ;
8071 return ;
8172 default :
82- cmn_err ( CE_PANIC , "bad int len %d" , len );
73+ PANIC ( "bad int len %d" , len );
8374 }
8475}
8576
@@ -96,13 +87,13 @@ ldv(int len, const void *addr)
9687 case 8 :
9788 return (* (uint64_t * )addr );
9889 default :
99- cmn_err ( CE_PANIC , "bad int len %d" , len );
90+ PANIC ( "bad int len %d" , len );
10091 }
10192 return (0xFEEDFACEDEADBEEFULL );
10293}
10394
10495void
105- zap_leaf_byteswap (zap_leaf_phys_t * buf , int size )
96+ zap_leaf_byteswap (zap_leaf_phys_t * buf , size_t size )
10697{
10798 zap_leaf_t l ;
10899 dmu_buf_t l_dbuf ;
@@ -119,10 +110,10 @@ zap_leaf_byteswap(zap_leaf_phys_t *buf, int size)
119110 buf -> l_hdr .lh_prefix_len = BSWAP_16 (buf -> l_hdr .lh_prefix_len );
120111 buf -> l_hdr .lh_freelist = BSWAP_16 (buf -> l_hdr .lh_freelist );
121112
122- for (int i = 0 ; i < ZAP_LEAF_HASH_NUMENTRIES (& l ); i ++ )
113+ for (uint_t i = 0 ; i < ZAP_LEAF_HASH_NUMENTRIES (& l ); i ++ )
123114 buf -> l_hash [i ] = BSWAP_16 (buf -> l_hash [i ]);
124115
125- for (int i = 0 ; i < ZAP_LEAF_NUMCHUNKS (& l ); i ++ ) {
116+ for (uint_t i = 0 ; i < ZAP_LEAF_NUMCHUNKS (& l ); i ++ ) {
126117 zap_leaf_chunk_t * lc = & ZAP_LEAF_CHUNK (& l , i );
127118 struct zap_leaf_entry * le ;
128119
@@ -160,11 +151,11 @@ void
160151zap_leaf_init (zap_leaf_t * l , boolean_t sort )
161152{
162153 l -> l_bs = highbit64 (l -> l_dbuf -> db_size ) - 1 ;
163- zap_memset (& zap_leaf_phys (l )-> l_hdr , 0 ,
154+ memset (& zap_leaf_phys (l )-> l_hdr , 0 ,
164155 sizeof (struct zap_leaf_header ));
165- zap_memset (zap_leaf_phys (l )-> l_hash , CHAIN_END ,
156+ memset (zap_leaf_phys (l )-> l_hash , CHAIN_END ,
166157 2 * ZAP_LEAF_HASH_NUMENTRIES (l ));
167- for (int i = 0 ; i < ZAP_LEAF_NUMCHUNKS (l ); i ++ ) {
158+ for (uint_t i = 0 ; i < ZAP_LEAF_NUMCHUNKS (l ); i ++ ) {
168159 ZAP_LEAF_CHUNK (l , i ).l_free .lf_type = ZAP_CHUNK_FREE ;
169160 ZAP_LEAF_CHUNK (l , i ).l_free .lf_next = i + 1 ;
170161 }
@@ -185,7 +176,7 @@ zap_leaf_chunk_alloc(zap_leaf_t *l)
185176{
186177 ASSERT (zap_leaf_phys (l )-> l_hdr .lh_nfree > 0 );
187178
188- int chunk = zap_leaf_phys (l )-> l_hdr .lh_freelist ;
179+ uint_t chunk = zap_leaf_phys (l )-> l_hdr .lh_freelist ;
189180 ASSERT3U (chunk , < , ZAP_LEAF_NUMCHUNKS (l ));
190181 ASSERT3U (ZAP_LEAF_CHUNK (l , chunk ).l_free .lf_type , = = , ZAP_CHUNK_FREE );
191182
@@ -223,28 +214,29 @@ zap_leaf_array_create(zap_leaf_t *l, const char *buf,
223214{
224215 uint16_t chunk_head ;
225216 uint16_t * chunkp = & chunk_head ;
226- int byten = 0 ;
217+ int byten = integer_size ;
227218 uint64_t value = 0 ;
228219 int shift = (integer_size - 1 ) * 8 ;
229220 int len = num_integers ;
230221
231222 ASSERT3U (num_integers * integer_size , <=, ZAP_MAXVALUELEN );
232223
224+ if (len > 0 )
225+ value = ldv (integer_size , buf );
233226 while (len > 0 ) {
234227 uint16_t chunk = zap_leaf_chunk_alloc (l );
235228 struct zap_leaf_array * la = & ZAP_LEAF_CHUNK (l , chunk ).l_array ;
236229
237230 la -> la_type = ZAP_CHUNK_ARRAY ;
238231 for (int i = 0 ; i < ZAP_LEAF_ARRAY_BYTES ; i ++ ) {
239- if (byten == 0 )
240- value = ldv (integer_size , buf );
241232 la -> la_array [i ] = value >> shift ;
242233 value <<= 8 ;
243- if (++ byten == integer_size ) {
244- byten = 0 ;
245- buf += integer_size ;
234+ if (-- byten == 0 ) {
246235 if (-- len == 0 )
247236 break ;
237+ byten = integer_size ;
238+ buf += integer_size ;
239+ value = ldv (integer_size , buf );
248240 }
249241 }
250242
@@ -264,7 +256,7 @@ zap_leaf_array_free(zap_leaf_t *l, uint16_t *chunkp)
264256 * chunkp = CHAIN_END ;
265257
266258 while (chunk != CHAIN_END ) {
267- int nextchunk = ZAP_LEAF_CHUNK (l , chunk ).l_array .la_next ;
259+ uint_t nextchunk = ZAP_LEAF_CHUNK (l , chunk ).l_array .la_next ;
268260 ASSERT3U (ZAP_LEAF_CHUNK (l , chunk ).l_array .la_type , = = ,
269261 ZAP_CHUNK_ARRAY );
270262 zap_leaf_chunk_free (l , chunk );
@@ -333,7 +325,7 @@ zap_leaf_array_read(zap_leaf_t *l, uint16_t chunk,
333325
334326static boolean_t
335327zap_leaf_array_match (zap_leaf_t * l , zap_name_t * zn ,
336- int chunk , int array_numints )
328+ uint_t chunk , int array_numints )
337329{
338330 int bseen = 0 ;
339331
@@ -562,7 +554,7 @@ zap_entry_create(zap_leaf_t *l, zap_name_t *zn, uint32_t cd,
562554
563555 uint64_t valuelen = integer_size * num_integers ;
564556
565- int numchunks = 1 + ZAP_LEAF_ARRAY_NCHUNKS (zn -> zn_key_orig_numints *
557+ uint_t numchunks = 1 + ZAP_LEAF_ARRAY_NCHUNKS (zn -> zn_key_orig_numints *
566558 zn -> zn_key_intlen ) + ZAP_LEAF_ARRAY_NCHUNKS (valuelen );
567559 if (numchunks > ZAP_LEAF_NUMCHUNKS (l ))
568560 return (SET_ERROR (E2BIG ));
@@ -624,7 +616,7 @@ zap_entry_create(zap_leaf_t *l, zap_name_t *zn, uint32_t cd,
624616
625617 /* link it into the hash chain */
626618 /* XXX if we did the search above, we could just use that */
627- uint16_t * chunkp = zap_leaf_rehash_entry (l , chunk );
619+ uint16_t * chunkp = zap_leaf_rehash_entry (l , le , chunk );
628620
629621 zap_leaf_phys (l )-> l_hdr .lh_nentries ++ ;
630622
@@ -687,9 +679,8 @@ zap_entry_normalization_conflict(zap_entry_handle_t *zeh, zap_name_t *zn,
687679 */
688680
689681static uint16_t *
690- zap_leaf_rehash_entry (zap_leaf_t * l , uint16_t entry )
682+ zap_leaf_rehash_entry (zap_leaf_t * l , struct zap_leaf_entry * le , uint16_t entry )
691683{
692- struct zap_leaf_entry * le = ZAP_LEAF_ENTRY (l , entry );
693684 struct zap_leaf_entry * le2 ;
694685 uint16_t * chunkp ;
695686
@@ -722,7 +713,7 @@ zap_leaf_transfer_array(zap_leaf_t *l, uint16_t chunk, zap_leaf_t *nl)
722713 & ZAP_LEAF_CHUNK (nl , nchunk ).l_array ;
723714 struct zap_leaf_array * la =
724715 & ZAP_LEAF_CHUNK (l , chunk ).l_array ;
725- int nextchunk = la -> la_next ;
716+ uint_t nextchunk = la -> la_next ;
726717
727718 ASSERT3U (chunk , < , ZAP_LEAF_NUMCHUNKS (l ));
728719 ASSERT3U (nchunk , < , ZAP_LEAF_NUMCHUNKS (l ));
@@ -739,7 +730,7 @@ zap_leaf_transfer_array(zap_leaf_t *l, uint16_t chunk, zap_leaf_t *nl)
739730}
740731
741732static void
742- zap_leaf_transfer_entry (zap_leaf_t * l , int entry , zap_leaf_t * nl )
733+ zap_leaf_transfer_entry (zap_leaf_t * l , uint_t entry , zap_leaf_t * nl )
743734{
744735 struct zap_leaf_entry * le = ZAP_LEAF_ENTRY (l , entry );
745736 ASSERT3U (le -> le_type , = = , ZAP_CHUNK_ENTRY );
@@ -748,7 +739,7 @@ zap_leaf_transfer_entry(zap_leaf_t *l, int entry, zap_leaf_t *nl)
748739 struct zap_leaf_entry * nle = ZAP_LEAF_ENTRY (nl , chunk );
749740 * nle = * le ; /* structure assignment */
750741
751- (void ) zap_leaf_rehash_entry (nl , chunk );
742+ (void ) zap_leaf_rehash_entry (nl , nle , chunk );
752743
753744 nle -> le_name_chunk = zap_leaf_transfer_array (l , le -> le_name_chunk , nl );
754745 nle -> le_value_chunk =
@@ -766,7 +757,7 @@ zap_leaf_transfer_entry(zap_leaf_t *l, int entry, zap_leaf_t *nl)
766757void
767758zap_leaf_split (zap_leaf_t * l , zap_leaf_t * nl , boolean_t sort )
768759{
769- int bit = 64 - 1 - zap_leaf_phys (l )-> l_hdr .lh_prefix_len ;
760+ uint_t bit = 64 - 1 - zap_leaf_phys (l )-> l_hdr .lh_prefix_len ;
770761
771762 /* set new prefix and prefix_len */
772763 zap_leaf_phys (l )-> l_hdr .lh_prefix <<= 1 ;
@@ -777,7 +768,7 @@ zap_leaf_split(zap_leaf_t *l, zap_leaf_t *nl, boolean_t sort)
777768 zap_leaf_phys (l )-> l_hdr .lh_prefix_len ;
778769
779770 /* break existing hash chains */
780- zap_memset (zap_leaf_phys (l )-> l_hash , CHAIN_END ,
771+ memset (zap_leaf_phys (l )-> l_hash , CHAIN_END ,
781772 2 * ZAP_LEAF_HASH_NUMENTRIES (l ));
782773
783774 if (sort )
@@ -792,22 +783,22 @@ zap_leaf_split(zap_leaf_t *l, zap_leaf_t *nl, boolean_t sort)
792783 * but this accesses memory more sequentially, and when we're
793784 * called, the block is usually pretty full.
794785 */
795- for (int i = 0 ; i < ZAP_LEAF_NUMCHUNKS (l ); i ++ ) {
786+ for (uint_t i = 0 ; i < ZAP_LEAF_NUMCHUNKS (l ); i ++ ) {
796787 struct zap_leaf_entry * le = ZAP_LEAF_ENTRY (l , i );
797788 if (le -> le_type != ZAP_CHUNK_ENTRY )
798789 continue ;
799790
800791 if (le -> le_hash & (1ULL << bit ))
801792 zap_leaf_transfer_entry (l , i , nl );
802793 else
803- (void ) zap_leaf_rehash_entry (l , i );
794+ (void ) zap_leaf_rehash_entry (l , le , i );
804795 }
805796}
806797
807798void
808799zap_leaf_stats (zap_t * zap , zap_leaf_t * l , zap_stats_t * zs )
809800{
810- int n = zap_f_phys (zap )-> zap_ptrtbl .zt_shift -
801+ uint_t n = zap_f_phys (zap )-> zap_ptrtbl .zt_shift -
811802 zap_leaf_phys (l )-> l_hdr .lh_prefix_len ;
812803 n = MIN (n , ZAP_HISTOGRAM_SIZE - 1 );
813804 zs -> zs_leafs_with_2n_pointers [n ]++ ;
@@ -823,9 +814,9 @@ zap_leaf_stats(zap_t *zap, zap_leaf_t *l, zap_stats_t *zs)
823814 n = MIN (n , ZAP_HISTOGRAM_SIZE - 1 );
824815 zs -> zs_blocks_n_tenths_full [n ]++ ;
825816
826- for (int i = 0 ; i < ZAP_LEAF_HASH_NUMENTRIES (l ); i ++ ) {
827- int nentries = 0 ;
828- int chunk = zap_leaf_phys (l )-> l_hash [i ];
817+ for (uint_t i = 0 ; i < ZAP_LEAF_HASH_NUMENTRIES (l ); i ++ ) {
818+ uint_t nentries = 0 ;
819+ uint_t chunk = zap_leaf_phys (l )-> l_hash [i ];
829820
830821 while (chunk != CHAIN_END ) {
831822 struct zap_leaf_entry * le =
0 commit comments