FreeBSD ZFS
The Zettabyte File System

sys/zap_leaf.h

Go to the documentation of this file.
00001 /*
00002  * CDDL HEADER START
00003  *
00004  * The contents of this file are subject to the terms of the
00005  * Common Development and Distribution License (the "License").
00006  * You may not use this file except in compliance with the License.
00007  *
00008  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
00009  * or http://www.opensolaris.org/os/licensing.
00010  * See the License for the specific language governing permissions
00011  * and limitations under the License.
00012  *
00013  * When distributing Covered Code, include this CDDL HEADER in each
00014  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
00015  * If applicable, add the following below this CDDL HEADER, with the
00016  * fields enclosed by brackets "[]" replaced with your own identifying
00017  * information: Portions Copyright [yyyy] [name of copyright owner]
00018  *
00019  * CDDL HEADER END
00020  */
00021 /*
00022  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
00023  */
00024 
00025 #ifndef _SYS_ZAP_LEAF_H
00026 #define _SYS_ZAP_LEAF_H
00027 
00028 #include <sys/zap.h>
00029 
00030 #ifdef  __cplusplus
00031 extern "C" {
00032 #endif
00033 
00034 struct zap;
00035 struct zap_name;
00036 struct zap_stats;
00037 
00038 #define ZAP_LEAF_MAGIC 0x2AB1EAF
00039 
00041 #define ZAP_LEAF_CHUNKSIZE 24
00042 
00048 #define ZAP_LEAF_NUMCHUNKS(l) \
00049         (((1<<(l)->l_bs) - 2*ZAP_LEAF_HASH_NUMENTRIES(l)) / \
00050         ZAP_LEAF_CHUNKSIZE - 2)
00051 
00056 #define ZAP_LEAF_ARRAY_BYTES (ZAP_LEAF_CHUNKSIZE - 3)
00057 
00058 #define ZAP_LEAF_ARRAY_NCHUNKS(bytes) \
00059         (((bytes)+ZAP_LEAF_ARRAY_BYTES-1)/ZAP_LEAF_ARRAY_BYTES)
00060 
00068 #define ZAP_LEAF_LOW_WATER (20)
00069 
00076 #define ZAP_LEAF_HASH_SHIFT(l) ((l)->l_bs - 5)
00077 #define ZAP_LEAF_HASH_NUMENTRIES(l) (1 << ZAP_LEAF_HASH_SHIFT(l))
00078 
00084 #define ZAP_LEAF_CHUNK(l, idx) \
00085         ((zap_leaf_chunk_t *) \
00086         ((l)->l_phys->l_hash + ZAP_LEAF_HASH_NUMENTRIES(l)))[idx]
00087 #define ZAP_LEAF_ENTRY(l, idx) (&ZAP_LEAF_CHUNK(l, idx).l_entry)
00088 
00089 typedef enum zap_chunk_type {
00090         ZAP_CHUNK_FREE = 253,
00091         ZAP_CHUNK_ENTRY = 252,
00092         ZAP_CHUNK_ARRAY = 251,
00093         ZAP_CHUNK_TYPE_MAX = 250
00094 } zap_chunk_type_t;
00095 
00096 #define ZLF_ENTRIES_CDSORTED (1<<0)
00097 
00101 typedef struct zap_leaf_phys {
00102         struct zap_leaf_header {
00106                 uint64_t lh_block_type;         
00107                 uint64_t lh_pad1;
00108                 uint64_t lh_prefix;             
00109                 uint32_t lh_magic;              
00110                 uint16_t lh_nfree;              
00111                 uint16_t lh_nentries;           
00112                 uint16_t lh_prefix_len;         
00117                 uint16_t lh_freelist;           
00118                 uint8_t lh_flags;               
00119                 uint8_t lh_pad2[11];
00121         } l_hdr; 
00131         uint16_t l_hash[1];
00132 } zap_leaf_phys_t;
00133 
00134 typedef union zap_leaf_chunk {
00135         struct zap_leaf_entry {
00136                 uint8_t le_type;                
00137                 uint8_t le_value_intlen;        
00138                 uint16_t le_next;               
00139                 uint16_t le_name_chunk;         
00140                 uint16_t le_name_numints;       
00141                 uint16_t le_value_chunk;        
00142                 uint16_t le_value_numints;      
00143                 uint32_t le_cd;                 
00144                 uint64_t le_hash;               
00145         } l_entry;
00146         struct zap_leaf_array {
00147                 uint8_t la_type;                
00148                 uint8_t la_array[ZAP_LEAF_ARRAY_BYTES];
00149                 uint16_t la_next;               
00150         } l_array;
00151         struct zap_leaf_free {
00152                 uint8_t lf_type;                
00153                 uint8_t lf_pad[ZAP_LEAF_ARRAY_BYTES];
00154                 uint16_t lf_next;       
00155         } l_free;
00156 } zap_leaf_chunk_t;
00157 
00158 typedef struct zap_leaf {
00159         krwlock_t l_rwlock;
00160         uint64_t l_blkid;       
00161         int l_bs;               
00162         dmu_buf_t *l_dbuf;
00163         zap_leaf_phys_t *l_phys;
00164 } zap_leaf_t;
00165 
00166 
00167 typedef struct zap_entry_handle {
00172         uint64_t zeh_num_integers;
00173         uint64_t zeh_hash;
00174         uint32_t zeh_cd;
00175         uint8_t zeh_integer_size;
00176 
00182         uint16_t zeh_fakechunk;
00183         uint16_t *zeh_chunkp;
00184         zap_leaf_t *zeh_leaf;
00186 } zap_entry_handle_t;
00187 
00195 extern int zap_leaf_lookup(zap_leaf_t *l,
00196     struct zap_name *zn, zap_entry_handle_t *zeh);
00201 extern int zap_leaf_lookup_closest(zap_leaf_t *l,
00202     uint64_t hash, uint32_t cd, zap_entry_handle_t *zeh);
00203 
00212 extern int zap_entry_read(const zap_entry_handle_t *zeh,
00213     uint8_t integer_size, uint64_t num_integers, void *buf);
00214 
00215 extern int zap_entry_read_name(struct zap *zap, const zap_entry_handle_t *zeh,
00216     uint16_t buflen, char *buf);
00217 
00223 extern int zap_entry_update(zap_entry_handle_t *zeh,
00224     uint8_t integer_size, uint64_t num_integers, const void *buf);
00225 
00229 extern void zap_entry_remove(zap_entry_handle_t *zeh);
00230 
00238 extern int zap_entry_create(zap_leaf_t *l, struct zap_name *zn, uint32_t cd,
00239     uint8_t integer_size, uint64_t num_integers, const void *buf,
00240     zap_entry_handle_t *zeh);
00241 
00245 extern boolean_t zap_entry_normalization_conflict(zap_entry_handle_t *zeh,
00246     struct zap_name *zn, const char *name, struct zap *zap);
00247 
00248 /*
00249  * Other stuff.
00250  */
00251 
00252 extern void zap_leaf_init(zap_leaf_t *l, boolean_t sort);
00253 extern void zap_leaf_byteswap(zap_leaf_phys_t *buf, int len);
00254 extern void zap_leaf_split(zap_leaf_t *l, zap_leaf_t *nl, boolean_t sort);
00255 extern void zap_leaf_stats(struct zap *zap, zap_leaf_t *l,
00256     struct zap_stats *zs);
00257 
00258 #ifdef  __cplusplus
00259 }
00260 #endif
00261 
00262 #endif /* _SYS_ZAP_LEAF_H */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines