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 #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 
  37 extern int fzap_default_block_shift;
  38 
  39 #define ZAP_MAGIC 0x2F52AB2ABULL
  40 
  41 #define FZAP_BLOCK_SHIFT(zap)   ((zap)->zap_f.zap_block_shift)
  42 
  43 #define MZAP_ENT_LEN            64
 
 123                 uint64_t zt_blks_copied; /* number source blocks copied */
 124         } zap_ptrtbl;
 125 
 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 */
 130         uint64_t zap_normflags;         /* flags for u8_textprep_str() */
 131         uint64_t zap_flags;             /* zap_flags_t */
 132         /*
 133          * This structure is followed by padding, and then the embedded
 134          * pointer table.  The embedded pointer table takes up second
 135          * half of the block.  It is accessed using the
 136          * ZAP_EMBEDDED_PTRTBL_ENT() macro.
 137          */
 138 } zap_phys_t;
 139 
 140 typedef struct zap_table_phys zap_table_phys_t;
 141 
 142 typedef struct zap {
 143         objset_t *zap_objset;
 144         uint64_t zap_object;
 145         struct dmu_buf *zap_dbuf;
 146         krwlock_t zap_rwlock;
 147         boolean_t zap_ismicro;
 148         int zap_normflags;
 149         uint64_t zap_salt;
 150         union {
 151                 struct {
 152                         /*
 153                          * zap_num_entries_mtx protects
 154                          * zap_num_entries
 155                          */
 156                         kmutex_t zap_num_entries_mtx;
 157                         int zap_block_shift;
 158                 } zap_fat;
 159                 struct {
 160                         int16_t zap_num_entries;
 161                         int16_t zap_num_chunks;
 162                         int16_t zap_alloc_next;
 
 179 
 180 typedef struct zap_name {
 181         zap_t *zn_zap;
 182         int zn_key_intlen;
 183         const void *zn_key_orig;
 184         int zn_key_orig_numints;
 185         const void *zn_key_norm;
 186         int zn_key_norm_numints;
 187         uint64_t zn_hash;
 188         matchtype_t zn_matchtype;
 189         char zn_normbuf[ZAP_MAXNAMELEN];
 190 } zap_name_t;
 191 
 192 #define zap_f   zap_u.zap_fat
 193 #define zap_m   zap_u.zap_micro
 194 
 195 boolean_t zap_match(zap_name_t *zn, const char *matchname);
 196 int zap_lockdir(objset_t *os, uint64_t obj, dmu_tx_t *tx,
 197     krw_t lti, boolean_t fatreader, boolean_t adding, zap_t **zapp);
 198 void zap_unlockdir(zap_t *zap);
 199 void zap_evict(dmu_buf_t *db, void *vmzap);
 200 zap_name_t *zap_name_alloc(zap_t *zap, const char *key, matchtype_t mt);
 201 void zap_name_free(zap_name_t *zn);
 202 int zap_hashbits(zap_t *zap);
 203 uint32_t zap_maxcd(zap_t *zap);
 204 uint64_t zap_getflags(zap_t *zap);
 205 
 206 #define ZAP_HASH_IDX(hash, n) (((n) == 0) ? 0 : ((hash) >> (64 - (n))))
 207 
 208 void fzap_byteswap(void *buf, size_t size);
 209 int fzap_count(zap_t *zap, uint64_t *count);
 210 int fzap_lookup(zap_name_t *zn,
 211     uint64_t integer_size, uint64_t num_integers, void *buf,
 212     char *realname, int rn_len, boolean_t *normalization_conflictp);
 213 void fzap_prefetch(zap_name_t *zn);
 214 int fzap_count_write(zap_name_t *zn, int add, uint64_t *towrite,
 215     uint64_t *tooverwrite);
 216 int fzap_add(zap_name_t *zn, uint64_t integer_size, uint64_t num_integers,
 217     const void *val, dmu_tx_t *tx);
 218 int fzap_update(zap_name_t *zn,
 219     int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx);
 | 
 
 
   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  * Copyright (c) 2014 Spectra Logic Corporation, All rights reserved.
  25  */
  26 
  27 #ifndef _SYS_ZAP_IMPL_H
  28 #define _SYS_ZAP_IMPL_H
  29 
  30 #include <sys/zap.h>
  31 #include <sys/zfs_context.h>
  32 #include <sys/avl.h>
  33 
  34 #ifdef  __cplusplus
  35 extern "C" {
  36 #endif
  37 
  38 extern int fzap_default_block_shift;
  39 
  40 #define ZAP_MAGIC 0x2F52AB2ABULL
  41 
  42 #define FZAP_BLOCK_SHIFT(zap)   ((zap)->zap_f.zap_block_shift)
  43 
  44 #define MZAP_ENT_LEN            64
 
 124                 uint64_t zt_blks_copied; /* number source blocks copied */
 125         } zap_ptrtbl;
 126 
 127         uint64_t zap_freeblk;           /* the next free block */
 128         uint64_t zap_num_leafs;         /* number of leafs */
 129         uint64_t zap_num_entries;       /* number of entries */
 130         uint64_t zap_salt;              /* salt to stir into hash function */
 131         uint64_t zap_normflags;         /* flags for u8_textprep_str() */
 132         uint64_t zap_flags;             /* zap_flags_t */
 133         /*
 134          * This structure is followed by padding, and then the embedded
 135          * pointer table.  The embedded pointer table takes up second
 136          * half of the block.  It is accessed using the
 137          * ZAP_EMBEDDED_PTRTBL_ENT() macro.
 138          */
 139 } zap_phys_t;
 140 
 141 typedef struct zap_table_phys zap_table_phys_t;
 142 
 143 typedef struct zap {
 144         dmu_buf_user_t zap_dbu;
 145         objset_t *zap_objset;
 146         uint64_t zap_object;
 147         struct dmu_buf *zap_dbuf;
 148         krwlock_t zap_rwlock;
 149         boolean_t zap_ismicro;
 150         int zap_normflags;
 151         uint64_t zap_salt;
 152         union {
 153                 struct {
 154                         /*
 155                          * zap_num_entries_mtx protects
 156                          * zap_num_entries
 157                          */
 158                         kmutex_t zap_num_entries_mtx;
 159                         int zap_block_shift;
 160                 } zap_fat;
 161                 struct {
 162                         int16_t zap_num_entries;
 163                         int16_t zap_num_chunks;
 164                         int16_t zap_alloc_next;
 
 181 
 182 typedef struct zap_name {
 183         zap_t *zn_zap;
 184         int zn_key_intlen;
 185         const void *zn_key_orig;
 186         int zn_key_orig_numints;
 187         const void *zn_key_norm;
 188         int zn_key_norm_numints;
 189         uint64_t zn_hash;
 190         matchtype_t zn_matchtype;
 191         char zn_normbuf[ZAP_MAXNAMELEN];
 192 } zap_name_t;
 193 
 194 #define zap_f   zap_u.zap_fat
 195 #define zap_m   zap_u.zap_micro
 196 
 197 boolean_t zap_match(zap_name_t *zn, const char *matchname);
 198 int zap_lockdir(objset_t *os, uint64_t obj, dmu_tx_t *tx,
 199     krw_t lti, boolean_t fatreader, boolean_t adding, zap_t **zapp);
 200 void zap_unlockdir(zap_t *zap);
 201 void zap_evict(void *dbu);
 202 zap_name_t *zap_name_alloc(zap_t *zap, const char *key, matchtype_t mt);
 203 void zap_name_free(zap_name_t *zn);
 204 int zap_hashbits(zap_t *zap);
 205 uint32_t zap_maxcd(zap_t *zap);
 206 uint64_t zap_getflags(zap_t *zap);
 207 
 208 #define ZAP_HASH_IDX(hash, n) (((n) == 0) ? 0 : ((hash) >> (64 - (n))))
 209 
 210 void fzap_byteswap(void *buf, size_t size);
 211 int fzap_count(zap_t *zap, uint64_t *count);
 212 int fzap_lookup(zap_name_t *zn,
 213     uint64_t integer_size, uint64_t num_integers, void *buf,
 214     char *realname, int rn_len, boolean_t *normalization_conflictp);
 215 void fzap_prefetch(zap_name_t *zn);
 216 int fzap_count_write(zap_name_t *zn, int add, uint64_t *towrite,
 217     uint64_t *tooverwrite);
 218 int fzap_add(zap_name_t *zn, uint64_t integer_size, uint64_t num_integers,
 219     const void *val, dmu_tx_t *tx);
 220 int fzap_update(zap_name_t *zn,
 221     int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx);
 |